actor should move when button is pressed but not continue to move if button is held in

When pressing a key my actor moves to specific predifined xy locations in the scene, but when the key is held-in, the actor moves through all those locations in a cycle.

Is there a way that once the key is pressed and even held in, the actor will only move once, to the next predefined location. Only once the button is released and pressed again, the actor should move to the next predefined location?

Thanks!

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Can you show how you have your rules set up?

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

  • revoltandreverbrevoltandreverb Member Posts: 159
    Hi Tatiang. yea sure, here it is http://grab.by/ux3u
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2014
    Your rules are set up nicely but I do see the problem. If you're holding down the "right" key then each of your rules is going to trigger in succession as soon as the self.position.X values are correct for that rule.

    You might try adding a condition to each rule that checks if attribute game.allowMove (boolean) is true. Set that attribute to true initially. Inside of the movement rule, set it up this way:

    [Interpolate or change self.positionX (see note below)]
    Change attribute game.allowMove to false

    Then add a rule that says When key "right" is up, change attribute game.allowMove to true.

    Is there a reason you're using an Interpolate behavior with duration set to 0? I would think it would be simpler to just use a Change Attribute behavior to change self.position.X.

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

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited February 2014
    Hi @revoltandreverb, good advice from @tatiang as always.

    You could also try something like this: (note: I've included it as a loop, not sure if that's what you're after; also as mentioned by @tatiang, the Interpolate needs a duration, otherwise it's pointless to use, you might as well use a Change Attribute...so I've given the interpolates a duration)

    Make an integer attribute, let's call it Trigger, it's value at the default 0.

    So your Rules now:

    Change Attribute self.Position.X to 20

    --First Move
    When key right is down and Trigger = 1
    Interpolate self.Position.X to 60 Duration 0.2

    --Second Move
    When key right is down and Trigger=2
    Interpolate self.Position.X to 100 Duration 0.2

    --Third Move
    When key right is down and Trigger=3
    Interpolate self.Position.X to 20 Duration 0.2

    Rule: When key right is up
    Rule: --nested in above rule-- When Trigger=0
    Change Attribute Trigger to 1
    Otherwise
    When Trigger=1
    Change Attribute Trigger to 2
    Otherwise
    When Trigger=2
    Change Attribute Trigger to 3
    Otherwise
    When Trigger=3
    Change Attribute Trigger to 1

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • revoltandreverbrevoltandreverb Member Posts: 159
    Firstly, thanks for the insane support. I set the interpolate duration to 0, to make the position change very fast as apposed to 1 second, for some reason GS wouldn't allow me to set decimals like 0.1, 0.2 etc. I've only been using GS for a week. The only reason I used interpolate was because move to was very buggy and I read on the forum that I should rather use interpolate instead of move to. What is the difference between "move to" and interpolate?

    After this post I incidentally switched to self.pos while working through a GS book I purchased on Amazon.

    Anyway, Tatiang your logic worked perfectly, thanks! Gyroscope I wasn't specifically looking to do it in a loop per se, is there any advantage to the way you've done it compared to Tatiang method?

    I've purchased 2 GS books on Amazon and while it's a great learning tool to work through examples, I'm just wondering if you guys can point me in the right direction with regards to fundamentals. I just feel if I had better foundation for example with booleans and their best uses, perhaps I would have been able to come up with a solution myself with the problem I had. Currently it feels to only way to learn is to work through game tutorials, which is great, but it's not necessarily helping me with problems I come across in my games. Any advice?

    Thanks
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @revoltandreverb I wish there was a catch-all tutorial but learning GameSalad is really a process that takes time. Game tutorials are great, and the Cookbook is good for reference (both early on and when you get into the nitty gritty of things), and eventually pulling apart a template from some of the veteran developers here can teach you a lot once you understand GameSalad well, but it's still a process.

    Move To is basically an Interpolate behavior that is restricted to changing the x and y values (or two interpolate behaviors if you want to be technical). I don't much about why it seems to be buggy but I've heard that from people. I've never used it because of that. I would think Interpolate set to 0 seconds would be identical to change attribute but I guess I'd have to test that to know for sure. Anyway, you should absolutely be able to enter decimals for Interpolate durations. Are you in a country that uses commas between whole and decimal numbers (0,5 instead of 0.5)? It looks like it from your screenshot but maybe it's just blurry.

    The only drawback in terms of using Interpolate is that it doesn't handle collision rules well. You can also use a Move behavior with the speed determined by the number of pixels you need to move. So a speed of 60 is 60 pixels per second. And of course, you can use all sorts of fancy math formulas in the speed field to generate any sort of relational or proportional speed you want.

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

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

    Agree with @tatiang, GameSalad Creator has a definite learning curve, just like any other software... but keep at it, and it'll all click into place bit by bit for you, I'm certain...

    It's good you've bought two manuals, I'm sure they'll be good, but for the fundamentals, there is an official GameSalad Manual: you can download it via the Help tab at the top of this web page.

    In answer to your question about any advantage in my method over that given by @tatiang, the answer is.... no! Just a different way... (most of us guys and gals who help out here, especially those that have been doing it for a long time, are sometimes compelled to help - to answer - even if there's one solution already given! "For the record" I guess...)

    As to the loop, you only need it to loop if you need it to loop, but anyhow, thinking about it, yours loop back anyway, to 20, so I didn't really add anything new, forgot I said I'd added the loop... :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Sign In or Register to comment.