actor should move when button is pressed but not continue to move if button is held in
revoltandreverb
Member Posts: 159
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!
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
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
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
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
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
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
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