HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Variable length on events?

02-13-2008, 09:42 PM#1
Gwypaas
Is there anyway I can use variable length on events?
I tried using this:
Collapse JASS:
call TriggerRegisterTimerEvent(CreateTowers, HowOften, true)
call TriggerAddAction( CreateTowers, function NewTower)
The "HowOften" is a real declared as a global and im changing it in another trigger but when I test the map it doesn't affect how often it runs.
02-13-2008, 09:54 PM#2
Anitarf
That's because the event is created with the current value of the variable, not linked to the variable. However the variable changes afterwards, the event will remain the same. You can not do what you want without destroying the trigger and remaking it when you change the value of the variable.
02-13-2008, 10:04 PM#3
TaintedReality
The easiest way would probably be to just use a timer.
02-14-2008, 12:35 AM#4
Toadcop
yes use self launching timer like that
Collapse JASS:
globals
  real tmr_period=0.025
  string tmr_res_func="InitialTimerStart"
  timer tmt_tmr=CreateTimer()
endglobals

function tmr_action_restart takes nothing returns nothing
//
    ...your actions
    set tmr_period=GetRandonReal(0.01,0.05) // change the period randomly every time.
//
// at the function end you will restart the timer with the currect period
    call ExecuteFunc(tmr_res_func)
endfunction

function InitialTimerStart takes nothing returns nothing
    call TimerStart(tmr_tmr,tmr_period,false,function tmr_action_restart)
endfunction

well it must work =) you can also use TriggerEvaluate. but ExecuteFunc is simpler for the begin ;)