I need help with percentages

0 favourites
  • 13 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Im doing a simple outbreak game, is a turn based game.

    I have in the gam several areas, each area have those variables:

    • population
    • cleaness
    • isolation
    • infected
    • deaths
    • recovered

    And some global variables:

    • infection_rate
    • recovery_rate
    • turn_number
    • cycle_number

    My logic is simple:

    Each turn i do this:

    add to area.infected area.population*(infection_rate*0.02)/100

    the 0.02 value is a rate of in this case 2% for isolation below 40

    But the number go up too fast, more like 20% instead of 2%

    any help or advise of how do this math better.

    Ps: each cycle that is two turns i do the math for deaths count.. basicaly is this:

    add to area.deaths area.infected*0.02

    this number also go up high very fast

  • if you are updating those variables every tick, then that will be happening 60 times a second.

    Your math looks fine, so it is probably running more times than you expect. We would have to see your code to be able to help more.

  • Which of these variables are absolute values, and which are relative (percentages)? What is the value of infection_rate?

  • if you are updating those variables every tick, then that will be happening 60 times a second.

    Your math looks fine, so it is probably running more times than you expect. We would have to see your code to be able to help more.

    is not for every tick this heapens on a buton click that i run the logic as a function

  • Which of these variables are absolute values, and which are relative (percentages)? What is the value of infection_rate?

    all of them are absolute numbers, the only percentages are infection_rate and recovery rate.

    as i mentioned on the expression i also put a 0.02 value simulating a 2% for areas with isolation below 50.

    Isolation are values from 0 to 100

  • Yeah, you need to post your code. Is it possible that you are processing areas multiple times? For example, if you have a loop and not picking the right area instance inside the loop, then "infected" variable will be incremented for all areas several times each turn.

  • (0.02/100) is not 2%, that's 0.02%. So if the isolation is 40-50, you are adding only 0.02%, but if the isolation is 10-20, you are adding 3.02%, which is 150 times more! Maybe that's why you are seeing such a big difference in numbers sometimes.

    Other than that I think your formulas are working correctly.

    But your code is extremely inefficient. Are you planning to duplicate events 23-57 for other 8 areas? This is a terribly wrong approach, don't do this!!

    Use a single sprite object for all 9 areas (make 9 instances of it). Or add all 9 areas into a family. Use the family in all events and you will be able to optimize your code by 80-90%!

  • (0.02/100) is not 2%, that's 0.02%. So if the isolation is 40-50, you are adding only 0.02%, but if the isolation is 10-10, you are adding 3.02%, which is 150 times more! Maybe that's why you are seeing such a big difference in numbers sometimes.

    Other than that I think your formulas are working correctly.

    But your code is extremely inefficient. Are you planning to duplicate events 23-57 for other 8 areas? This is a terribly wrong approach, don't do this!!

    Use a single sprite object for all 9 areas (make 9 instances of it). Or add all 9 areas into a family. Use the family in all events and you will be able to optimize your code by 80-90%!

    Can you give me a example of the code?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You already have Areas family. To start using it you need to move all variables from sprites to the family level. Check out this tutorial:

    construct.net/en/tutorials/upgrade-object-family-319

    But it may be even easier just to use one sprite Area with 9 instances. (delete all other area sprites).

  • If you use one sprite, your function will look like this:

    You will only need ~20 events, instead of 200.

  • You already have Areas family. To start using it you need to move all variables from sprites to the family level. Check out this tutorial:

    https://www.construct.net/en/tutorials/upgrade-object-family-319

    But it may be even easier just to use one sprite Area with 9 instances. (delete all other area sprites).

    I meant for the percentages

  • What about the percentages? I told you, the problem may be because with certain isolation/cleaness values your formulas are adding only 0.02% to the infected, but with other values they might add 1.02-3.02%, this is a huge difference. Maybe the infection_rate value should be 2, not 0.02

    .

    With 45 isolation and 100K people: 100000*(0.02)/100 = 20 infected

    With 15 isolation and 100K people: 100000*(0.02+3)/100 = 3020 infected

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