• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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