Math question about percentages

0 favourites
  • 4 posts
From the Asset Store
Logo Quiz with 150 prepared logos and answers, automatic question and answer mixing
  • 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. :)

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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! :)

  • a bit simpler healthState.capx

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)