Graphics

 View Only
  • 1.  If statement inside a For loop

    Posted 06-06-2018 21:59
    Hi everyone,

    I'm having an issue with IF statements inside a FOR loop. My loop works fine if I don't use any conditionals inside, but once I add a conditional, it'll only calculate the first item, but won't continue after that. I've tried this script on an Event script in a scene director, I've also tried using it OnRender, but it always fails to continue after the first item. I ended up doing a workaround with Visual Logic, but I wanted to script this so that I could change out elements more easily, or copy and paste the script into a new scene and just have everything picked up without having to relink a ton of stuff in VL.

    Any help is appreciated. I'm running Developer 6.5.

    Here's my script:
    Dim winReveal, correctReveal as xpSceneDirector
    Dim winGap, winNoGap, displayCorrect, ardyReveal, displayMask as xpBaseObject
    Dim choiceCount, correctChoice, choiceWinner, questionStage, displayWinLabel as xpTextObject
    Dim choiceIndex, i as Integer

    'Gets the choice count and win reveal Scene director
    Scene.GetSceneDirectorByName("WinReveal", winReveal)
    Scene.GetSceneDirectorByName("CorrectReveal", correctReveal)
    Scene.GetObjectByName("DATALINQ - CHOICE COUNT", choiceCount)
    Scene.GetObjectByName("DATALINQ - STAGE", questionStage)

    choiceIndex = choiceCount.Text

    If questionStage.Text = "stop" then

    For i = 1 to choiceIndex

    Scene.GetObjectByName("DATALINQ - RANK - CHOICE " & i, choiceWinner)
    Scene.GetObjectByName("DATALINQ - CORRECT - CHOICE " & i, correctChoice)
    Scene.GetObjectByName("GROUP - DISPLAY - GAP WIN - CHOICE " & i, winGap)
    Scene.GetObjectByName("GROUP - DISPLAY - NO GAP WIN - CHOICE " & i, winNoGap)
    Scene.GetObjectByName("LAYER - DISPLAY - CORRECT - CHOICE " & i, displayCorrect)

    If choiceWinner.Text = "1" AND correctChoice.Text = "1" then

    displayCorrect.Visible = 1
    winGap.Visible = 1
    winNoGap.Visible = 0

    Else If choiceWinner.Text = "1" AND correctChoice.Text = "0" then

    displayCorrect.Visible = 0
    winGap.Visible = 0
    winNoGap.Visible = 1

    Else If choiceWinner.Text = "0" AND correctChoice.Text = "1" then

    displayCorrect.Visible = 1
    winGap.Visible = 0
    winNoGap.Visible = 0

    End If

    Next

    End If 'End questionStage


  • 2.  RE: If statement inside a For loop

    Posted 06-07-2018 10:01
    Code seems OK, check the name of your objects (space in names can be tricky ) :

    for example does "DATALINQ - RANK - CHOICE 2" exists or is it named "DATALINQ - RANK - CHOICE2" (no space before the number ).


    #XPression


  • 3.  RE: If statement inside a For loop

    Posted 06-07-2018 12:53
    I think the issue is you need to convert your integer i counter variable to a string, so your GetObjectByName should be this for each.
    Scene.GetObjectByName("DATALINQ - RANK - CHOICE " & Cstr(i), choiceWinner)


    Prior to the if statement, I would also debug the values you are testing. What do they actually equal?

    Engine.DebugMessage("correctChoice.Text: " + correctChoice.Text,1)


    Hope that helps.
    Mike

    #XPression