• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Real Conversion

Status
Not open for further replies.
Level 16
Joined
Mar 27, 2011
Messages
1,349
For an experience system, I am calculating the experience gained from killing enemies. The "GhostExperienceMultiplier" is a real variable. For this instances, lets assume the variable equals 1.25. Here's the action:

  • Hero - Add ((Supply used by (Triggering unit)) x (Integer(GhostExperienceMultiplier))) experience to (Picked unit), Show level-up graphics
Since I converted the real into an integer, will it still have a value of 1.25, or will it be rounded off to 1 (since integers don't have decimal values)?
 
It will have a value of 1.

Note that conversion doesn't do rounding. It just truncates (cuts off at the decimal). e.g.: 1.245 converted to integer would be 1. 5.9999 would be converted to 5. Rounding requires a formula:
JASS:
function RoundToInteger takes real n returns nothing
    if n > 0 then
        return R2I(n + 0.5)
    endif
    return R2I(n - 0.5)
endfunction
 
Level 11
Joined
Dec 19, 2012
Messages
411
Since experience system can't has real number, so if you want to make you experience system work like real, you would need to have a real variable array that used to store the experience for the heroes. Just check if the variable has increased by killing mobs and convert them to integer and give the converted experience to heroes ( variable - hero's current experience ).
 
Status
Not open for further replies.
Top