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

Using a real variable in Game - Periodic Event

Status
Not open for further replies.
Level 3
Joined
May 9, 2009
Messages
25
I'm trying to make a spawn trigger with a speed that can be modified in-game. I have a real variable, GameSpeed, and want to base the spawn time on that. There are currently 5 different spawn types with another 15 or so in planning, as well as a few other triggers that I would like to base on the variable.

However, the map doesnt show any defined Real variables when I edit the 'Periodic Event' event. Why is this? and is there any way to go around it/ make it work?

Thanks in advance.
 

sPy

sPy

Level 21
Joined
Apr 10, 2009
Messages
268
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Before doing your trigger, make an init trigger first. --------
      • -------- Why? Because we're going to add the event of the trigger by using an action. --------
      • -------- Look below. --------
      • Set RealVariable = 5.00
      • Trigger - Add to Periodic Time <gen> the event (Time - Every RealVariable seconds of game time)
      • -------- Why are we doing this? Because you can use variables by adding the events with this action. --------
      • -------- Now you don't have to put any event at the trigger, because you added it already from here. --------
  • Periodic Time
    • Events
    • Conditions
    • Actions
      • -------- Actions here --------
      • -------- Simple enough? --------
 
Level 3
Joined
May 9, 2009
Messages
25
Alright, I can make that work. Thanks, +rep.

But why doesnt the WE allow it when you're setting the action in the trigger?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
The reason is cause there is no "variable" type in jass. All events take arguments and bind based on what arguments are they are passed. As such there is no room for a "variable" to be bound into an event.

You can however use variables to provide the arguments for binding events. The trigger above shows this. This means that the event gets bound with what ever the value of the variable is at the time of binding.

If I remember there is some event which can use a string of the name of a vairable to bind a variable to it. This however is a once off event (for getting changes in the variable if I remember).
native TriggerRegisterVariableEvent takes trigger whichTrigger,string varName,limitop opcode,real limitval returns event
This only works on some variable types.

You could trigger some form of system of events which take variables as arguments if it were not for the problem that there is no event for handle variables or no destructor for events.

I guess blizzard was sloppy with WC3 events... Like they were with the Preload native and a million other things.
 
Level 15
Joined
Oct 16, 2010
Messages
941
Create a periodic that goes off every .1 seconds (or .01 seconds if you want it to be really accurate) and keep a variable count of the total time thats passed. When that count equals the global real that you've set then run through all your actions.

EX:

  • Periodic
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Set Periodic_Count = (Periodic_Count + 0.01)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Periodic_Count Greater than or equal to Spawn_Interval
        • Then - Actions
          • Set Periodic_Count = 0.00
          • -------- PLACE ACTIONS HERE --------
        • Else - Actions
You can set the global real Spawn_Interval to whatever you want. It represents how long the peroidic will go. However, if you set the Spawn_Interval to something less than what the Periodic_Count is currently at, then it will run in the next .01 seconds. If you don't want it to run instantly when you set it to something low, then you need to reset the Peroidic_Count to 0.
 
This one's even simpler;
  • Timer Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Just set the last number to what you want. --------
      • Countdown Timer - Start Timer as a Repeating timer that will expire in 0.01 seconds
  • Periodic
    • Events
      • Time - Timer expires
    • Conditions
    • Actions
      • -------- actions --------
 
Level 2
Joined
Mar 1, 2022
Messages
9
This one's even simpler;
  • Timer Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Just set the last number to what you want. --------
      • Countdown Timer - Start Timer as a Repeating timer that will expire in 0.01 seconds
  • Periodic
    • Events
      • Time - Timer expires
    • Conditions
    • Actions
      • -------- actions --------
Wow..
this really helped me alot! that is much simpler and more accurate.
now i can set the speed of omnislash using a variable (20/agility amount) thank you.

btw feel free to try my rpg map at epicwar.com, just search for name on "author".
because of you now every can enjoy a good omnislash!
 
Status
Not open for further replies.
Top