Math: Modulator (Mod) Operator Problem

Griffen25

New Member
Reaction score
1
been awhile since my calculus days;
I'm currently using a real variable as a timer, deducting 0.2 seconds from it at each interval and updating/displaying it in the form of a floating text.

however, I would like it so that each time the real is equal to a whole number (integer) to change the floating text colour to white, instead of red. So it appears to be almost blinking.

This is what I've tried, can somebody help me please!



Trigger:
  • Fortify Timer
    • Events
      • Time - Every 0.20 seconds of game time
    • Conditions
    • Actions
      • Game - Display to Player Group - Player 1 (Red) for 0.33 seconds the text: Fortify Timer is on
      • For each (Integer A) from 1 to FO_Max, do (Actions)
        • Loop - Actions
          • -------- - - - - - - - --------
          • -------- - - - - - - - --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • FO_Time[(Integer A)] Greater than 0.00
            • Then - Actions
              • -------- - - - - - - - --------
              • -------- - - - - - - - --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                  • (FO_Time[(Integer A)] mod 1.00) Equal to 0.00
                • Then - Actions
                  • Game - Display to Player Group - Player 1 (Red) for 0.50 seconds the text: MOD Trigger
                  • Floating Text - Change the color of FO_Floating_Text[(Integer A)] to (100.00%, 100.00%, 100.00%) with 0.00% transparency
                • Else - Actions
                  • Floating Text - Change the color of FO_Floating_Text[(Integer A)] to (100.00%, 0.00%, 0.00%) with 0.00% transparency
              • -------- - - - - - - - --------
              • -------- - - - - - - - --------
              • Floating Text - Change text of FO_Floating_Text[(Integer A)] to (Substring((String((FO_Time[(Integer A)] - 0.20))), 1, 4)) using font size 11.00
              • Set FO_Time[(Integer A)] = (FO_Time[(Integer A)] - 0.20)
              • -------- - - - - - - - --------
              • -------- - - - - - - - --------
            • Else - Actions
              • Floating Text - Destroy FO_Floating_Text[(Integer A)]


It's getting late and my head is hurting, but I could have sworn that this was right. however worldedit doesnt seem to agree with me =P

Trigger:
  • (FO_Time[(Integer A)] mod 1.00) Equal to 0.00
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Are you using another trigger to deduct the 0.20 from the real variable? I don't see that anywhere in this trigger.

Also, try displaying the value of the variable, to make sure it's not offset by some value between 0.00 and 0.199.
 

cryowraith

New Member
Reaction score
7
I'm pretty sure mod only works on integers.

7 mod 3 = 1
4 mod 3 = 1
1 mod 1 = 0
2 mod 1 = 0
X mod 1 = 0

Get it?

If you want to check whether a real number is a round number or not, perhaps you could try this:
Multiply the real by 10 then mod it by 10.
So...
7.2*10 mod 10 = 2
7.0*10 mod 10 = 0

Or perhaps there is a math function that checks for round numbers? :p

If you could understand JASS and maths you could take a look here http://www.thehelper.net/forums/showthread.php?t=140220
 

Rushhour

New Member
Reaction score
46
wouldn't something like

CustomScript if R2I(FO_Time[(Integer A)])==FO_Time[(Integer A)] then

work too?
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Trigger:
  • [...]
    • If - Conditions
      • Or - Any (Conditions) are true
        • Conditions
      • (FO_Time[(Integer A)] mod 1.00) Equal to 0.00
    • Then - Actions
Your problem there is in the condition - you appear to have an extra, unused "Or" there, with nothing in it, which is making the whole condition always false.

I'm pretty sure mod only works on integers.
Nah, it works on reals too.

CustomScript if R2I(FO_Time[(Integer A)])==FO_Time[(Integer A)] then
Yeah, that's another way, which in GUI would be
Trigger:
  • Real(Integer(FO_Time[(Integer A)])) Equal to FO_Time[(Integer A)]
 

Griffen25

New Member
Reaction score
1
strange...

7.2*10 mod 10 = 2
7.0*10 mod 10 = 0

huh. I got a strange result;
(note: 25 is my starting value)

250.000 % 10 = 0.000
248.000 % 10 = 8.000
246.000 % 10 = 6.000
244.000 % 10 = 4.000
242.000 % 10 = 2.000
240.000 % 10 = 10.000
238.000 % 10 = 8.000
236.000 % 10 = 6.000
234.000 % 10 = 4.000
232.000 % 10 = 2.000
230.000 % 10 = 10.000
228.000 % 10 = 8.000
226.000 % 10 = 6.000​

but that is fixable. I'll just make it whenever its equal to 10.000 or 0.000
its a dodgy fix but it should work. I'll let you know how it turns out.

------------------------------------------
EDIT: I Got it :thup:, its a little hard to read and I would not submit it anywhere, but it does work. If I get the time I will try and refine it.

Trigger:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • ((FO_Time[(Integer A)] x 10.00) mod 10.00) Equal to 0.00
          • ((FO_Time[(Integer A)] x 10.00) mod 10.00) Equal to 2.00
    • Then - Actions
    • Floating Text - Change the color of FO_Floating_Text[(Integer A)] to (100.00%, 100.00%, 100.00%) with 0.00% transparency
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top