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.
  • jonas jonas:
    Cool, enjoy your vacation!
  • The Helper The Helper:
    Have a great vacation Tom!
  • The Helper The Helper:
    Happy Friday Night!
    +1
  • V-SNES V-SNES:
    Happy Friday Night!
    +1
  • The Helper The Helper:
    Going out of a town for the weekend will be back sunday night! Hope everyone has a great weekend!
    +2
  • The Helper The Helper:
    Happy Monday!
  • Ghan Ghan:
    Monday? Speak for yourself. :p
    +2
  • The Helper The Helper:
    Happy Taco Tuesday!
    +1
  • The Helper The Helper:
    Tacos! :)
  • The Helper The Helper:
    Check out the discord for taco pictures :) You cannot put pictures in this chat
    +1
  • The Helper The Helper:
    Damn here come the bots again - 193 online but they are totally invisible to any stats - bunch of bots!'
  • C cubanismo:
    Re: Taco Tuesday, if there were some way to share edible tacos over the internet, technology would be complete.
    +2
  • The Helper The Helper:
    One can only wish!
  • tom_mai78101 tom_mai78101:
    I'm back from Taiwan
    +1
  • The Helper The Helper:
    I am reorganizing the site I know nobody will notice but I am not done quite yet but the main forums order has been changed and there is a new news category in Other News which is all the remaining headline news stuff not categorized - Headline News is just the stuff that shows on the main page now and the news archive is off the main forums page
  • The Helper The Helper:
    and the real archive lives off of headline news
  • The Helper The Helper:
    Happy Monday!

    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