User tip! Never exceed a value again.

AtlantenAtlanten Member, PRO Posts: 56
edited November -1 in Working with GS (Mac)
There has been quite a few posts on the forum about values growing too big despite rules and conditions etc.

I thought I'd share a technique that has been really useful for me, and instantly made my projects cleaner and more readable.

It's described in the Wiki, but it's so short that I didn't understand it first. (I'm not used to the math world)

It's the "min" and "max" functions. You can use them to limit values, like this:

If condition is true: change attribute x to min(50,x+1)

So what this does is it chooses whichever number is smaller, 50 or x+1

x will increase by 1 until it reaches 50, then it will just be 50 after that.

You use "max" the same way, except in this case you will get the larger number.

Never exceed a value again...

Hope this helps someone!

Comments

  • ktfrightktfright Member Posts: 964
    that sounds good on paper, but could you apply that as an example of something?
  • AtlantenAtlanten Member, PRO Posts: 56
    It is basically a rule like this:

    if x>y then change x to y

    But you don't need to make another rule to add to your long list of rules, you can just put it into the expression.

    Here's an example from the forum:

    http://gamesalad.com/forums/topic.php?id=589#post-3168

    Reading the comments of that post, I realise that's what SMDG is saying, he just didn't explain it!
  • quantumsheepquantumsheep Member Posts: 8,188
    Ah - I thought I'd read something about min and max somewhere, just couldn't remember.

    Nice one Atlanten - I'll go through my games and slip this in!

    Thanks a lot!

    QS :)
  • AtlantenAtlanten Member, PRO Posts: 56
    Cool! You're very welcome.
Sign In or Register to comment.