Why isn't this code working!
MattButlerStudios
Member Posts: 486
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
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?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I don't understand the problem, but could you use 2 variables?
@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.
www.mbstudios.co | Free Stuff
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.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang That seems to explain my issue. Thanks!
www.mbstudios.co | Free Stuff
@MattButlerStudios said:
Hi @MattButlerStudios To eliminate any values changed/used by section 1 in section 2, use the Otherwise:
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
@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.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
OK, thanks Tatian - I misread the problem. (Though using the Otherwise in that situation should still be OK, I'm thinking... )
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
@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.
www.mbstudios.co | Free Stuff
Hi, it was @Tatiang agreeing with you there - I suggested the Otherwise option - I win some, I lose some...
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
@gyroscope Yeah I know. Just wanted to clarify in case someone had another option.
www.mbstudios.co | Free Stuff
OK 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.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
@gyroscope Yeah I finally got it working. The problem occurred due to Gamesalad not waiting for the loops to finish before changing the attribute.
www.mbstudios.co | Free Stuff