Math question about percentages

Get help using Construct 2

Post » Fri Apr 13, 2012 6:01 am

This is for the programmers out there.

I'm trying to figure out how to write this loop.

Psuedocode :
If your Health is between 70% to 100%, you are strong.
If your Health is between 40% to 69%, you are weak.
If you Health is between 1% to 39%, you are dying.

What's the best way to write this?

More info : If say, your health's maximum value changes? Maybe at level 1, you have 100 health. But at level 2, you have 112 health. Right now I'm using hard numbers, but I'd prefer to be more like a programmer. :)
B
20
S
5
G
5
Posts: 66
Reputation: 4,515

Post » Fri Apr 13, 2012 7:25 am

There are many ways to do this. I've included 2 ways in this capx. (One is toggled disabled. They both produce the same result, but there might be a use for each. The first is easiest to understand.

RandomHealth.capx

Variables are used for all of the health range limits, so if you want to change the health range levels you just change the values for the globals. In the comments I included your original numbers so that you can see more easily what is going on.

B
29
S
11
G
12
Posts: 281
Reputation: 11,888

Post » Fri Apr 13, 2012 2:17 pm

Oh I get it! Global variables and writing the values there! I was getting really close to that solution, but your method is was more organized and cleaner. Thanks! :)
B
20
S
5
G
5
Posts: 66
Reputation: 4,515

Post » Fri Apr 13, 2012 7:43 pm

a bit simpler healthState.capx
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346


Return to How do I....?

Who is online

Users browsing this forum: linkman2004, Renfd, supreme676 and 21 guests