Loops / periodics

Handless

New Member
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
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
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
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
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.
  • Jesus4Lyf Jesus4Lyf:
    Hmm, how to summarize... Moved to the USA and got married. Became a professional software engineer and solution lead. Learning Godot for game dev. :)
  • jonas jonas:
    So you are pursuing game dev as a hobby? What industry is your dayjob in?
  • jonas jonas:
    FAANG?
  • Jesus4Lyf Jesus4Lyf:
    Not quite FAANG, less pay for a less hours/stress. Yeah, game dev as a hobby.
  • jonas jonas:
    makes sense. Do we have a hobby game dev subforum to showcase some work?
  • Blackveiled Blackveiled:
    Happy Thursday
    +1
  • The Helper The Helper:
    Happy Thursday!
  • The Helper The Helper:
    TGIF!
  • The Helper The Helper:
    hey tom_mai please do not archive anymore news
  • Ghan Ghan:
    AMD Ryzen 7000 next week :D
    +1
  • The Helper The Helper:
    noice!
  • tom_mai78101 tom_mai78101:
    "hey tom_mai please do not archive anymore news" ----> Got it. What should we do with the "News Archive" subforum?
  • The Helper The Helper:
    I think leave it for real old news that cannot be sorted the reason we had it in the first place was a server issue that we do not have anymore. I don't want to get rid of the archive just not put anything in it for now until we figure it out more
  • The Helper The Helper:
    The side chat has nothing on the discord. it is not possible but the biggest thing on my wish list right now is a sidechat channel on the disord that hooks up to this...
  • Ghan Ghan:
    I've been selected for the Diablo IV beta.
    +1
  • Ghan Ghan:
    Woo!
    +1
  • The Helper The Helper:
    that is so cool
  • V-SNES V-SNES:
    Eh just noticed the new discord section on the side. Looks great!
    +1
  • Blackveiled Blackveiled:
    :( feels bad I can't ever get selected for any beta I sign up for. It's annoying as heck.
    +1
  • The Helper The Helper:
    Hello mgarcia! Happy Monday everyone!
  • The Helper The Helper:
    Happy Tuesday! :)

    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