prevent negative value in variable

Get help using Construct 2

Post » Sun Nov 17, 2013 2:58 am

I have a variable score which reduces if player does the wrong thing. How ever if player does the wrong thing on start of game I get a score of say -50 how do I a void this and ensure d least value score can hold is 0. Thanks
B
15
S
4
Posts: 138
Reputation: 2,003

Post » Sun Nov 17, 2013 3:16 am

the max() expression returns the smallest value of any amount of numbers given

so
max(4,2,6)

will return 2

in your case you can do:
set score to max(score,0)

which means if score is below 0, it will just return 0

min() works in the opposite way

other related expressions are clamp() and abs(), you can find them with a description in the 'objects with expressions' window, in system.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Sun Nov 17, 2013 3:17 am

Use the max() expression. max returns whatever value is greater.

For example
Set score to max(score - 50, 0)
will only subtract until 0 is reached, from then on it will return 0

@keepee beat me to it tulamide2013-11-17 03:17:46
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Sun Nov 17, 2013 3:26 am

Thanks, works perfectly
B
15
S
4
Posts: 138
Reputation: 2,003


Return to How do I....?

Who is online

Users browsing this forum: combotg, Lancifer and 9 guests