Graphics

 View Only
  • 1.  Loop

    Posted 06-16-2015 00:51
    What is wrong in rhis loop?

    dim objRedBlue as xpTextObject

    dim objBkg as xpBaseObject

    dim objMat as xpMaterial

    dim i as Integer

    for i = 1 to 6

    Self.GetObjectByName("Kreds_bkg" & i, objBkg)

    Self.GetObjectByName("Kreds_farve" & i, objRedBlue)

    if objRedBlue.text = "B" then

    Engine.GetMaterialByName("Blue", objMat)

    else if objRedBlue.text = "R" then

    Engine.GetMaterialByName("Red", objMat)

    end if

    objBkg.SetMaterial(0, objMat)

    next i


    When I put this in 6 times, everything works:

    dim objRedBlue as xpTextObject

    dim objBkg as xpBaseObject

    dim objMat as xpMaterial

    dim i as Integer

    Self.GetObjectByName("Kreds_bkg 1", objBkg)

    Self.GetObjectByName("Kreds_farve 1", objRedBlue)

    if objRedBlue.text = "B" then

    Engine.GetMaterialByName("Blue", objMat)

    else if objRedBlue.text = "R" then

    Engine.GetMaterialByName("Red", objMat)

    end if

    objBkg.SetMaterial(0, objMat)




  • 2.  RE: Loop

    Posted 06-16-2015 01:09
    It probably can't find the objects, so it will exit when you try to access objBkg because it is null.. Make sure you turn on the debug monitor for scripting option so you can see the error messages it returns.

    In the loop code you provided, it is looking for an object called "Kreds_bkg1" (no space), and in your example without the loop it is looking for "Kres_bkg 1" (with a space).

    #XPression


  • 3.  RE: Loop

    Posted 06-17-2015 00:40
    In both these lines, I had to add a space

    Self.GetObjectByName("Kreds_bkg" & i, objBkg)

    Self.GetObjectByName("Kreds_farve" & i, objRedBlue)


    The code now looks like this (and works!):

    dim objRedBlue as xpTextObject

    dim objBkg as xpBaseObject

    dim objMat as xpMaterial

    dim i as Integer

    for i = 1 to 6

    Self.GetObjectByName("Kreds_bkg " & i, objBkg)

    Self.GetObjectByName("Kreds_farve " & i, objRedBlue)

    if objRedBlue.text = "B" then

    Engine.GetMaterialByName("Blue", objMat)

    else if objRedBlue.text = "R" then

    Engine.GetMaterialByName("Red", objMat)

    end if

    objBkg.SetMaterial(0, objMat)

    next i



    #XPression