Why isn't this code working!

The code outline is as follows:

When condition is true:
-variable = 1
-run a loop

-variable = 2
-run a loop

The problem is that when I get to the second section, the variable is not changed and the same variable from section one is used. (variable = 1 the whole time). Does anyone know why this is happening? Code reads from top to bottom so they should be able to be changed and used appropriately right?

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    -variable = 1

    Does this mean "When attribute=1" or does it mean "Change Attribute to 1" ? And how are you making sure that the second part of that rule only starts after the first loop ends?

  • zweg25zweg25 Member Posts: 738

    I don't understand the problem, but could you use 2 variables?

  • MattButlerStudiosMattButlerStudios Member Posts: 486

    @tatiang @zweg25 Sorry for the poor explanation. Variable = 1 really mean change attribute variable to 1. I thought that the code ran down in order so I wouldn't have to specify that it should start after the first loop had ended.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    GameSalad code does execute from top to bottom but it does so very quickly so that if you have something that takes a long time such as a loop or timer, it won't wait for that to complete before executing the next rule or behavior.

  • MattButlerStudiosMattButlerStudios Member Posts: 486

    @tatiang That seems to explain my issue. Thanks!

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited February 2015

    @MattButlerStudios said:

    The problem is that when I get to the second section, the variable is not changed and the same variable from section one is used. (variable = 1 the whole time). Does anyone know why this is happening? Code reads from top to bottom so they should be able to be changed and used appropriately right?

    Hi @MattButlerStudios To eliminate any values changed/used by section 1 in section 2, use the Otherwise:

    When condition is true:
    -variable = 1
    -run a loop
    Otherwise
    -variable = 2
    -run a loop>
    
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @gyroscope that's a bit different from what he's trying to do. He wants the first loop to run with a certain attribute set to 1 and the second loop to run with that same attribute set to 2.

    The attributes are not part of rule conditions but rather just used inside of the loops.

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited February 2015

    OK, thanks Tatian - I misread the problem. :smile: (Though using the Otherwise in that situation should still be OK, I'm thinking... :wink: )

  • MattButlerStudiosMattButlerStudios Member Posts: 486

    @tatiang @gyroscope I came up with a solution that unfortunately requires me to re-write lots of code. In total I have about 6 separate loops inside of the rule so I'm not sure if otherwise would be a viable option anyway.

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    Hi, it was @Tatiang agreeing with you there - I suggested the Otherwise option - I win some, I lose some... :wink:

  • MattButlerStudiosMattButlerStudios Member Posts: 486

    @gyroscope Yeah I know. Just wanted to clarify in case someone had another option. :smile:

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited February 2015

    OK :smile: Looking at what you've written again, the problem then doesn't seem to be with the programming of two rules, more to do with whatever changes your variable from 1 to 2....

    But you say you've rewritten your Rules/behaviours so I'm guessing all's well now.

  • MattButlerStudiosMattButlerStudios Member Posts: 486

    @gyroscope Yeah I finally got it working. The problem occurred due to Gamesalad not waiting for the loops to finish before changing the attribute.

Sign In or Register to comment.