ActorSpeed Stop?

Games4lifeGames4life 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

  • DevirosDeviros Member, PRO Posts: 87
    edited December 2015

    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;
    }

  • DevirosDeviros Member, PRO Posts: 87

    And in gamesalad friendly blocks:

  • Games4lifeGames4life Member, PRO Posts: 279

    @Deviros said:
    And in gamesalad friendly blocks:

    Ah, thanks very much! I think this works!

  • DevirosDeviros Member, PRO Posts: 87
    edited December 2015

    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.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    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

  • SocksSocks London, UK.Member Posts: 12,822

    @Deviros said:
    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;
    }

    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.

  • Games4lifeGames4life Member, PRO Posts: 279

    @Socks said:

    @Deviros said:
    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;
    }

    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?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    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

  • Games4lifeGames4life Member, PRO Posts: 279

    @tatiang said:
    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. :)

    Yes, I forgot to mention the actor speed is set at 85.

    Thanks for your help!

  • DevirosDeviros Member, PRO Posts: 87

    @Socks said:

    @Deviros said:
    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;
    }

    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.

    @socks - Yea - i explained it that way too :p

  • SocksSocks London, UK.Member Posts: 12,822

    @Deviros said:
    @socks - Yea - i explained it that way too :p

    Oh yeah, just spotted your other post, yes agreed the second version is more efficient.

  • DevirosDeviros Member, PRO Posts: 87

    @Socks said:

    @Deviros said:
    @socks - Yea - i explained it that way too :p

    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 =/

Sign In or Register to comment.