Loops / periodics

Handless

New Member
Reaction score
2
Hello,

I'm trying to convert couple of my spells into jass to make them mui. However I'm a total jass noob so I ran into this problem.

I have a trigger that detects when the spell is casts, and another that runs periodically (every 0.07 sec). My problem is that I don't know how to combine them so they would use same locals..

I was thinking about changing the periodic trigger into a loop, but I can't make the delay between each loop to that 0.07 seconds, "call TriggerSleepAction( 0.07 )" always waits for 0.2 seconds or something. So how can I make this work?
 

chobibo

Level 1 Crypt Lord
Reaction score
48
That's possible, but you need to use a hashtable, or other systems, to be able to pull that off. You should tell us what the spell does or at least show us the gui triggers.
 

Handless

New Member
Reaction score
2
Thanks. Now my only problem is to make it MUI..

Note that is just a test trigger, my real spell is way too long and complicated to put here (the structure is basically the same though). Anyways, the messages shows only once because of the GetTriggerUnit. How can I make it show multiple times, remember the correct unit, and still be MUI?

JASS:
function spell2 takes nothing returns nothing
    local unit u=GetTriggerUnit()
    local timer t=CreateTimer()
    call DisplayTextToForce( GetPlayersAll(), GetUnitName(u) )
    call TimerStart(t, 0.07, false, function spell2)
    set t=null
endfunction

//===========================================================================
function InitTrig_Melee_Initialization takes nothing returns nothing
    set gg_trg_Melee_Initialization = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Melee_Initialization, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( gg_trg_Melee_Initialization, function spell2 )
endfunction
 

Risen

New Member
Reaction score
4
I don't get what you mean by show multiple times; do you want that entire function ran or just that text message?

As for remembering the correct unit, you need to use hashtables. Depending on how you're using the unit's ID, you may just need to use TimerUtils and attach the data to a timer.

You should also considering using vJass for productivity and flexibility, I converted your above code for an example of how flexible it can be.
JASS:
scope SpellName initializer Init

private function actions takes nothing returns nothing
    local unit u=GetTriggerUnit() 
    local timer t=CreateTimer()
    call DisplayTextToForce( GetPlayersAll(), GetUnitName(u) )
    call TimerStart(t, 0.07, false, function spell2)
    call DestroyTimer( t ) //You must either recycle (TimerUtils) or destroy to prevent leaks.
    set t=null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( t, function actions )
    set t = null //Null it if you don't use it, it does leak.
endfunction

endscope
 

tooltiperror

Super Moderator
Reaction score
231
Your best bet is indeed going to be using vJASS. The JASSHelper Bible contains all the information on structs and teaches how to use them. Here's a quick example you should be able to understand.

JASS:

scope MySpell // requires TimerUtils

	struct Data
		unit caster
	endstruct

	function handlerFunc takes nothing returns nothing
		local timer t = GetExpiredTimer()
		local Data data = GetTimerData(t)
		call KillUnit(data.caster)
		call BJDebugMsg("It has been five seconds since the spell was cast.")
		call ReleaseTimer(t)
		set t = null
	endfunction

	function foo takes nothing returns nothing
		local Data data = Data.create()
		local timer t = NewTimer()
		set Data.caster=GetTriggerUnit()
		call SetTimerData(t, data)
		call TimerStart(t, 5.00, false, function handlerFunc)
	endfunction

endscope


This example uses the library TimerUtils which is pretty much a standard timer system. You can get more info about how to use timers and a more detailed explanation in my tutorial.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top