Expression Editor - Minimum
JGary321
Member Posts: 1,246
I am either really bad at understanding or this is a typo??
This is from the wiki, I would think the answer here would be 12....
min
Usage: min(x,y)
Return the smaller value of two numbers or variable values.
Example: min(12,35) = 25
This is from the wiki, I would think the answer here would be 12....
min
Usage: min(x,y)
Return the smaller value of two numbers or variable values.
Example: min(12,35) = 25
Comments
Use it to set a upper limit on something.
You would use it like this:
Let's say in your game you collect coins.
Every time you touch a coin in the game, the game.cointTotal increases by one.
Now let's say your wallet only holds 100 coins.
You COULD add in a Rule that says something like:
Rule
When game.coinTotal < 100
Change Attribute game.coinTotal To: game.coinTotal + 1
Or you COULD add a Rule that says something like this
Rule
When game.coinTotal > 100
Change Attribute game.coinTotal To: 100
The MIN function allows you to simplify and get rid of that extra Rule like this:
When Actor overlaps or collides with Actor of type Coin
Change Attribute game.coinTotal To: min(game.coinTotal+1,100)
The second number represents the upper limit.
It subtle, but getting rid of any extra Rules is very important on a resource-starved device like the iPhone!
You would use MAX in the opposite way to set a bottom limit on something.
Like this:
When my gun has been fired,
Change Attribute game.ammo To: max(game.ammo-1,0)
Hope this helps!
Joe
PS: Sorry you had to do a big write-up FMG. Just sleep well knowing you wrote it in vain... err...sleep well anyways..