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:
    Is the school system in your country similar to Chinese school system? I could never imagine being a teacher in a Chinese school, what's expected of students and teachers is just so different from what I'd be looking for as a teacher
  • vypur85 vypur85:
    A Levels is based on the UK syllabus offered internationally. So the syllabus is similar throughout different countries, taught in english.
  • vypur85 vypur85:
    I can't speak or write or read much chinese... Too difficult....... Which also makes my life here in china a lil difficult.
  • jonas jonas:
    Oh, I see. I thought Chinese version of A-levels :D
  • jonas jonas:
    I've been using the translate app a lot on my phone. take a photo, translate. take another photo, translate again :D
  • jonas jonas:
    it also has voice translation, my colleagues sometimes use that
  • jonas jonas:
    You came during the 0 covid policy right? How'd you get through quarantine? Did you have some help with the apps and green codes?
  • tom_mai78101 tom_mai78101:
    If you have any Chinese you need help with, let me know.
    +1
  • vypur85 vypur85:
    @jonas Those were the things I did too. Translate app and VPN are always the most important things to have to survive. Lol.
  • vypur85 vypur85:
    Yea I came last year. I was quarantined for about 30 days. Fml. The first day of my quarantine was the eve of Chinese new year last year. Fml again... Lol.
  • vypur85 vypur85:
    @tom_mai78101 IIRC you're from Taiwan right.
  • The Helper The Helper:
    I thought China had cracked down on having any foreign teachers?
  • vypur85 vypur85:
    Yeah I've heard of the news before. My school is still actively hiring foreign teachers. Not sure how things work now.
  • The Helper The Helper:
    yeah it is hard to get reliable information about that kind of stuff
  • The Helper The Helper:
    but you are doing it so it is still doable
  • vypur85 vypur85:
    I think it doesn't affect existing foreign teachers. Then again, its still weird that my school is hiring.
  • The Helper The Helper:
    Happy Monday people hope everyone has a fantastic week!
  • Ghan Ghan:
    Happy Monday?! That's a contradiction.
  • jonas jonas:
  • jonas jonas:
    please put this in the news section, it's crazy
  • tom_mai78101 tom_mai78101:
    Technically, you can post in the Headline News. Just posted your news there.
  • tom_mai78101 tom_mai78101:
    I'm not aware of you not being able to post news.
  • jonas jonas:
    I think technically I can I just forget how
    +1
  • The Helper The Helper:
    Happy Thursday!

    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