User tip! Never exceed a value again.
Atlanten
Member, PRO Posts: 56
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!
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
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!
Nice one Atlanten - I'll go through my games and slip this in!
Thanks a lot!
QS
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io