Controlling to order that code runs

jsunnbjsunnb Member Posts: 12
edited October 2012 in Working with GS (Mac)
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

Best Answer

  • RThurmanRThurman Posts: 2,881
    Accepted Answer
    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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Can you post a screenshot of your gameplay? I'm not getting the whole "2 actors for walk and run" idea. And if you can post a screenshot of your rules, we can probably figure out the problem.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • jsunnbjsunnb Member Posts: 12
    edited October 2012
    I uploaded the file so far (keep in mind I have a lot more planned for it, I just still have a lot more learning to do to get there)
    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?
  • boredaholicboredaholic Member Posts: 47
    Try setting the speed up as an attribute (if not already done) then when you click walk change attribute "speed" to 5 or when you click run change attribute "speed" to 10 and just have the two actors with the speed attribute, but when you click run it changes the main actor to which ever and vice versa. Not sure if that makes sense. Its been a very long day.
  • boredaholicboredaholic Member Posts: 47
    As in switch main actor (destroy/spawn)?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    As far as uploading a picture of my code.... I don't see an option for that anywhere. Am I missing it?
    See this thread: http://forums.gamesalad.com/discussion/37485/how-to-post-images-to-the-forum

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • jsunnbjsunnb Member Posts: 12
    edited October 2012
    This is the Player Code (blue ball that turns into an arrow)
    image

    This is the walk/run button code. They are basically identical, except they change separate booleans.
    image

    The pictures seem to work if you open them in separate windows/tab.... not sure why they don't show up here tho...
  • SolarPepperStudiosSolarPepperStudios Member Posts: 754
    I played the game and it seemed to work fine. What exactly are you trying to do with the walk and run?
  • jsunnbjsunnb Member Posts: 12
    Sorry about the pics not working, ill try again when I get home from work.

    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.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @jsunnb For some reason, the forums don't allow image posting from secure URLs. With Dropbox, you'd need to upload the images to your Public folder and share them from there.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • jsunnbjsunnb Member Posts: 12
    So for some reason dropbox doesn't do public folders for new users anymore. I'll have to figure out how to do this another way. But I promise I'll get the pics up ASAP.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @jsunnb I was worried about that. Sorry it's such a pain. You might have to use ImageShack or another image hosting service.

    @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

  • jsunnbjsunnb Member Posts: 12
    Finally got the images up, let me know if you have any suggestions on my code (PS there is a way to have DropBox make you a public folder, but it's hidden in the help files, I can send a link to any that want it)
  • boredaholicboredaholic Member Posts: 47
    your coding confuses me. why is it when "all" conditions are valid, walk AND run = false... wouldn't you do if condition is valid for run, change speed to 300, otherwise change attribute to 0.

    i keep scrolling and looking at it... what if you just add to the "otherwise" section, change attribute "game.player speed" to 0?
  • jsunnbjsunnb Member Posts: 12
    The reason for the attribute change is to make a statement that the click was inside of the walk/run button in an attempt to make it so the player doesn't move to the button when it's pressed.
  • boredaholicboredaholic Member Posts: 47
    i dont have enough experience to really help then, i'm sorry, i tried at least lol
  • jsunnbjsunnb Member Posts: 12
    The simplest way to say what I really need is this. I want the code for the walk/run actors to run before the code for the player actor. Is there a way to set priorities for actors?
  • dmilinovichiiidmilinovichiii Member Posts: 620
    edited October 2012
    I'm not really sure what you're trying to ask, but I'll try my best to answer it. Code runs from the top down. So, for example if you have the rules:

    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 :)
  • jsunnbjsunnb Member Posts: 12
    Well the walk/run buttons are 1 actor each that contain code and the player is another actor that contains code. The problem I'm having is the code within the player actor is running before the code in the walk/run button actors. So the program doesn't register that the click was inside the walk/run actors until after the player has already started to move there.

    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.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Three possible ways to prioritize actors' rules:

    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

  • jsunnbjsunnb Member Posts: 12
    Alright, I did end up finding a different way to do what I wanted (the walk and run button became one button) but I do hope to add a shooting element into this so ideally I'd like to have a second gun that allows you to choose a weapon so my current solution wouldn't work. But I'll try the bottom up method as well.

    thank you everyone for your efforts.
Sign In or Register to comment.