ActorSpeed Stop?
Games4life
Member, PRO Posts: 279
Hey GS Community,
I have my actor so that every 20 seconds the speed increases by 2. How do I set it so that when the actor speed reaches 91 per say it stops adding more speed every 20 seconds?
This is my rule:
Comments
Well, depending on how you approached this - there's a couple of ways, but, really the easiest is to wrap your action in a rule:
Every 20 seconds
if (game.actorSpeed <= 91) {
game.actorSpeed = game.actorSpeed + 2;
}
And in gamesalad friendly blocks:
Ah, thanks very much! I think this works!
Alternatively, depending on how you've written your whole project, you could wrap the timer itself in a rule
Which would be a far more efficient method.
Finally - consider using this method instead of GS timers:
http://forums.gamesalad.com/discussion/44707/timers-are-for-chumps-gs-optimization-tips/p1 - you can include your logic (the rule) right there with your timer.
Two ways: either embed that timer inside a rule that says When game.actorSpeed<91...*
...or Change Attribute game.actorSpeed to min(91,game.actorSpeed)
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
If you do it that way the timer will always be firing away, even when it's not needed.
I'd use the same method but place the check before the timer, so . . .
If speed <=91
--Every 20 seconds
----Increase speed.
So like this?
It depends what your expression is (it's hidden) but basically, yes. I say it depends because if you're adding 20 each time to game.actorSpeed and you're checking to see if it's less than 91, then at 90 (or 80 or whatever) it will still add 20 and you'll be over 91. If you're okay with that, then no problem.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Yes, I forgot to mention the actor speed is set at 85.
Thanks for your help!
@socks - Yea - i explained it that way too
Oh yeah, just spotted your other post, yes agreed the second version is more efficient.
...sometimes it takes me five posts to say what i could say in one with proper formatting and not treating it like a text message =/