• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

More Efficient Integer Decreasing?

Status
Not open for further replies.
Level 6
Joined
Aug 12, 2007
Messages
201
  • DoingStuffCheck
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) has buff Sleep) Equal to False
              • (Current order of (Picked unit)) Not equal to (Order(<Empty String>))
              • ((Picked unit) is A Hero) Equal to True
            • Then - Actions
              • Game - Display to (All players) the text: TestUnitIsMoving!
              • Set FatigueIndex[(Player number of (Owner of (Picked unit)))] = (FatigueIndex[(Player number of (Owner of (Picked unit)))] + 1)
            • Else - Actions
This is what I am using to change my Fatigue value during actions, and it fires only when the unit is not idling, but only if the unit in question is doing the action during that every 2 second check. If you order the unit to move in small bursts then it doesn't fire, or if you do a task or cast a spell in the period between the two second check then it doesn't realize either.

My problem with this though is that should I set it to something like 0.3 to catch all its actions, it increases Fatigue by 1 every time it catches the unit doing something, meaning my Fatigue value skyrockets very very quickly, when I only want it to increase by roughly 1 every 2 seconds.

What is the best way to fix this triggers function into this? My only thought is to use a real that updates in small fractions on each check that would equivallate into 1 per 2 seconds, only the issue being my current Fatigue value is an integer, and I'm not sure how to add a real to the integer without losing values and stuff since Integers can't have decimal points.
 
Last edited:
Level 9
Joined
Sep 28, 2004
Messages
365
You can do something like this inside your loop. Is not any more efficient though, but it will work. + 0.03 is up to you. Depending on the periodic event. If the periodic event is every 0.50 seconds then you change it to 0.50.

  • Set timer[(Player number of (Owner of (Picked unit)))] = (timer[(Player number of (Owner of (Picked unit)))] + 0.03)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • timer[(Player number of (Owner of (Picked unit)))] Greater than or equal to 1.00
    • Then - Actions
      • -------- Reset Timer --------
      • Set timer[(Player number of (Owner of (Picked unit)))] = 0.00
      • -------- Increase your fatigue index here --------
    • Else - Actions
 
Level 6
Joined
Aug 12, 2007
Messages
201
You can do something like this inside your loop. Is not any more efficient though, but it will work. + 0.03 is up to you. Depending on the periodic event. If the periodic event is every 0.50 seconds then you change it to 0.50.

  • Set timer[(Player number of (Owner of (Picked unit)))] = (timer[(Player number of (Owner of (Picked unit)))] + 0.03)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • timer[(Player number of (Owner of (Picked unit)))] Greater than or equal to 1.00
    • Then - Actions
      • -------- Reset Timer --------
      • Set timer[(Player number of (Owner of (Picked unit)))] = 0.00
      • -------- Increase your fatigue index here --------
    • Else - Actions

0.30, not 0.03 since that'd be crazy fast for what I need, but I think I'm getting how your trigger works. Whenever a player is doing anything, the timer starts to fill in and then once the timer reached 1 it adds itself to the Fatigue integer?
 
Level 13
Joined
May 11, 2008
Messages
1,198
i don't understand. aren't you omitting some of the trigger?

i think i understand what you're getting at...but i don't really know what you're looking for.
in the map i'm working on i was editing ghost walk from the hero invoker...it's a spell that someone made, trying to copy exactly the invoker hero since it was a challenge to the person. i'm using his timer stuff for my timers for my spells. i'm at my parent's place now but when i get back to my computer i'll pull up the triggers for you since i guess that'll help.

of course it's all in jass but i don't think jass is all that hard to use. i can use the system even though it uses structs and i don't really understand structs.
 
Level 6
Joined
Aug 12, 2007
Messages
201
I'll show you what I made from his piece here once I am done in a second making sure it works properly. I'm basically trying to fire an event every time the picked hero is not sitting idle.

  • DoingStuffCheck Copy
    • Events
      • Time - Every 0.30 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) has buff Sleep) Equal to False
              • (Current order of (Picked unit)) Not equal to (Order(<Empty String>))
              • ((Picked unit) is A Hero) Equal to True
            • Then - Actions
              • Set ActionCounter[(Player number of (Owner of (Picked unit)))] = (ActionCounter[(Player number of (Owner of (Picked unit)))] + 0.34)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ActionCounter[(Player number of (Owner of (Picked unit)))] Greater than or equal to 1.00
                • Then - Actions
                  • Set ActionCounter[(Player number of (Owner of (Picked unit)))] = 0.00
                  • Set FatigueIndex[(Player number of (Owner of (Picked unit)))] = (FatigueIndex[(Player number of (Owner of (Picked unit)))] + 1)
                  • Game - Display to (All players) the text: TriggerSuccessful!
                • Else - Actions
            • Else - Actions

Tada. Testing it now. Seems to work fine.
 
Level 13
Joined
May 11, 2008
Messages
1,198
really? but how do you check if the unit is idle? isn't that hard to do? what about just checking if the unit is moving or not? does that work? i saw another spell that did damage according to whether a unit was moving...maybe that trigger would have some useful code.

edit: does (Current order of (Picked unit)) Not equal to (Order(<Empty String>)) work?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
You check the units current order, and if it is the order you want charge it. If the unit is issued another order or something occurs meaning the current order is cancled (do this via another trigger), you then reset the staminia and stuff.

Also you can easilly bump integers to reals no problem as jass allows them to be set to both integer and real values.
local real r = 1 //is valid
local real s = 0.1 //also valid
local real t = 1/2 //also valid although the answer is 0 integer
local real u = 1.0/2 //valid with answer 0.5

To summarise, real fields axcept both integer and real values and convert them automatically to reals when required.

However the opposite is not present as it is a mono directional relationship. You will need to use special conversin natives to convert reals into integers. Failing to use these natives will result in save errors and inevitably prevent your map from compiling the trigger script when loading.
local integer i = 1 //is valid
local integer j = R2I(1.9) //is valid but truncated to 1.
local integer k = 1.1 // is not valid and will cause errors

This is bacuse of set thory that it behaves like this. Integers are a subset of rational fractions (all reals in WC3 are rational fractions) and so with converse implied logic you can sate that where as all integers are reals, all reals are not integers (the converse statmenet fails) and thus you can easy type cast in one direction (from integer to real) without any need for complex structures, the opposite (converse) is not the case.
 
Level 6
Joined
Aug 12, 2007
Messages
201
Yep SanKakU, no string is the string you use for when someone is not doing anything.

And Dr Super Good, I'm not putting the Real into the Integer, when the Real reaches 1 or greater, it adds a stand alone 1 to the integer unrelated to the real's value and resets the real, this way no conversion is necessary, and the 0.1 or 0.2 that spills over isn't fatally vital. I could have it so when the real is 3 it adds 1 to the integer or any other value.

I didn't do well in high school math but I remember that Integers are 1,2,3,4, etc, and Reals are 1,2,3 and the infinite values inbetween, 1.34, 3.567etc, 3.14. Can't add decimals to something that won't accept them.
 
Status
Not open for further replies.
Top