Controlling to order that code runs
I have a very simply game (hoping to make it more complicated as I learn more) but right now I have an actor that moves to whatever place you click on the scene. I wanted to be able to make it go 2 speeds, so I added 2 actors for walk and run. The problem is, when I click the walk or run actors, not only does it change the speed, the actor that moves also goes there. The only way I could think to fix this was to make 2 booleans that said if the click was inside either the walk or run actor, and have the move to behavior only run if both booleans were false (meaning the click was not inside the walk or run actor)
Unfortunately, the actor still goes there. At first I thought it was because I coded it wrong, but I now think it's because the code for move to the location runs faster than the code that changes the boolean. I was able to verify that by turning off run to completion (meaning I had to hold down the mouse button for the actor to completely move there) and when I turn it off, the actor barely moves and doesn't move any further because the click is inside one of the other actors. How can I have the boolean change before the actor moves OR is there a better way to do what I'm describing?
Thank you
Unfortunately, the actor still goes there. At first I thought it was because I coded it wrong, but I now think it's because the code for move to the location runs faster than the code that changes the boolean. I was able to verify that by turning off run to completion (meaning I had to hold down the mouse button for the actor to completely move there) and when I turn it off, the actor barely moves and doesn't move any further because the click is inside one of the other actors. How can I have the boolean change before the actor moves OR is there a better way to do what I'm describing?
Thank you
Best Answer
-
RThurman Posts: 2,881
I heard once that actors fire from the bottom up. So layering actors in the scene is important.
Inside an actor, the behaviors run from the top of the list down downward.
Answers
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
http://arcade.gamesalad.com/game/106719
As far as uploading a picture of my code.... I don't see an option for that anywhere. Am I missing it?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
This is the walk/run button code. They are basically identical, except they change separate booleans.
The pictures seem to work if you open them in separate windows/tab.... not sure why they don't show up here tho...
My hopes were that the speed would change, which it currently does. But most likely, the user isn't going to want the player to also travel in that direction when the run/walk is selected.
So ideally when run/walk is selected the speed will change, but the player will not move.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@SaladStraightShooter - any idea why that might be (img code with https URLs doesn't work)?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
i keep scrolling and looking at it... what if you just add to the "otherwise" section, change attribute "game.player speed" to 0?
Change Integer X to 1
Change Integer X to 0
Then afterwards, Integer X will equal 0. If you set it to:
Change Integer X to 0
Change Integer X to 1
Then Integer X will equal 1. I hope this answers you question
What I'm looking for is a way to have the walk/run button code run first so that the player will know not to move there. How do I stop the player from jumping the gun.
1. Combine the rules into a single actor.
2. Change a boolean value at the end of one actor's rules and then check for the value of that boolean at the beginning of the other actor's rules.
3. Use a timer to force one actor to wait a certain number of seconds before it runs any rules.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
thank you everyone for your efforts.