Hi guys, I'm fairly new to JASS (started learning about a couple days ago), and to this forum, since I want to migrate from making GUI spells to JASS coded ones, complete with MUI.
Here's a code that I made (again, I'm quite new) that creates a lightning between units. The lightning moves between units and will break if the units are within 2000 units apart.
Knowing that I triggered something in JASS that's finally MUI, I'd say I accomplished something but there's one problem. Since I'm using TriggerSleepAction (which I think is the Wait action in GUI), the minimum amount is about 0.1 seconds, which means the lightning updates its position every 0.1 seconds. This results in the lightning looking really choppy, as opposed to updating every 0.01 seconds which is very smooth. I tried starting another timer that lasts 0.01 seconds inside the loop, then making another loop after the timer which will exit when the mini timer is over, which then goes back to the first loop, updating the lightning positions (since I assumed loops will not trigger any other action below it until the exitwhen is met).
Here's what I mean:
Is there someway to refine this trigger? Or am I gonna delve further into the world of Hashtables, which I am also learning at the moment? And also while I'm it, can you guys help me out and point which leaks I need to clean up in my trigger?
Here's a code that I made (again, I'm quite new) that creates a lightning between units. The lightning moves between units and will break if the units are within 2000 units apart.
JASS:
function Trig_lightning_2_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A001'
endfunction
function fastremoveloc takes location a, location b returns nothing
call RemoveLocation(a)
call RemoveLocation(b)
endfunction
function clearall takes handle a, handle b, handle c, handle d, handle e returns nothing
set a = null
set b = null
set c = null
set d = null
set e = null
endfunction
function Trig_lightning_2_Actions takes nothing returns nothing
local unit source = GetSpellAbilityUnit()
local unit target = GetSpellTargetUnit()
local location sourceloc = GetUnitLoc(source)
local location targetloc = GetUnitLoc(target)
local lightning link
local real distancecheck
call AddLightningLoc("HWSB", sourceloc, targetloc)
set link = GetLastCreatedLightningBJ()
call fastremoveloc(sourceloc, targetloc)
loop
set sourceloc = GetUnitLoc(source)
set targetloc = GetUnitLoc(target)
set distancecheck = DistanceBetweenPoints(sourceloc, targetloc)
exitwhen distancecheck > 2000.00
call MoveLightningLoc(link, sourceloc, targetloc)
call fastremoveloc(sourceloc, targetloc)
call TriggerSleepAction(0.01)
endloop
call fastremoveloc(sourceloc, targetloc)
call DestroyLightningBJ(link)
//set source = null
//set target = null
//set sourceloc = null
//set targetloc = null
//set link = null
//set linktimer = null
call clearall(source, target, sourceloc, targetloc, link)
endfunction
//===========================================================================
function InitTrig_lightning_2 takes nothing returns nothing
set gg_trg_lightning_2 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_lightning_2, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_lightning_2, Condition( function Trig_lightning_2_Conditions ) )
call TriggerAddAction( gg_trg_lightning_2, function Trig_lightning_2_Actions )
endfunction
Here's what I mean:
JASS:
loop
set sourceloc = GetUnitLoc(source)
set targetloc = GetUnitLoc(target)
set distancecheck = DistanceBetweenPoints(sourceloc, targetloc)
exitwhen distancecheck > 2000.00
call StartTimerBJ(updatetimer, false, 0.01) //updatetimer is the minitimer
loop
exitwhen TimerGetRemaining(updatetimer) <= 0.00
endloop
call MoveLightningLoc(link, sourceloc, targetloc)
call fastremoveloc(sourceloc, targetloc) //fastremove is a function that I made
//call TriggerSleepAction(0.01)
Is there someway to refine this trigger? Or am I gonna delve further into the world of Hashtables, which I am also learning at the moment? And also while I'm it, can you guys help me out and point which leaks I need to clean up in my trigger?