• 🏆 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!

[Spell] Modulo not showing zero

Status
Not open for further replies.
Level 12
Joined
May 16, 2020
Messages
660
Hi guys,

I want to use Modulo within a loop to only trigger a function at certain intervals. However, the game refuses to give me 0, if for example I divide 0.25 / 0.25 --> rest = 0. As such the "IF Equal to 0.00" part never runs. Any idea what is wrong?

Here the trigger and in-game screenshot:

  • Life Drain Cast Loop
    • Events
      • Time - LD_Timer expires
    • Conditions
    • Actions
      • For each (Integer LD_Integer) from 1 to LD_Index, do (Actions)
        • Loop - Actions
          • Set VariableSet LD_Counter[LD_Integer] = (LD_Counter[LD_Integer] + 0.05)
          • Game - Display to (All players) the text: (String((LD_Counter[LD_Integer] mod 0.25)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (LD_Counter[LD_Integer] mod 0.25) Equal to 0.00
            • Then - Actions
              • Game - Display to (All players) the text: Damage
              • Unit - Cause LD_Caster[LD_Integer] to damage LD_Target[LD_Integer], dealing LD_Drained_HP[LD_Integer] damage of attack type Spells and damage type Magic
              • Unit - Set life of LD_Caster[LD_Integer] to ((Life of LD_Caster[LD_Integer]) + LD_Drained_HP[LD_Integer])
            • Else - Actions
          • XXX
Capture.png
 
Last edited:
Level 5
Joined
Jul 31, 2020
Messages
103
It's because you're trying to use equal to compare real numbers. The numbers you enter might look fine to you, being exactly 0.1, 0.15, whatever. Even the game displaying them to you up to 3 decimals might look mighty fine to you, but what's actually happening is something akin to the actual number being 0.15, then about nineteen zeros, then some random number at the end. There is an explanation as to why this is the case, but it's fully technical, and boring. Long story short: don't use equals for reals because it won't work. If it somehow does work once in a blue moon randomly, you're one of the luckiest people left on this planet.
 
Status
Not open for further replies.
Top