- Joined
- Dec 17, 2017
- Messages
- 39
Hello,
im slowly getting into jass and as im discovering new possibilities, it seems i have to rework a lot of already done stuff in my map.
to the topic:
what is better (more efficient, lesser leaks if any): doing the periodical effect of a pushback with
a) a periodical event (my old Trigger):
or
b) with local timers:
or is there a better way?
thanks in advance
im slowly getting into jass and as im discovering new possibilities, it seems i have to rework a lot of already done stuff in my map.
to the topic:
what is better (more efficient, lesser leaks if any): doing the periodical effect of a pushback with
a) a periodical event (my old Trigger):
-
pushBack1
-
Ereignisse
-
Zeit - Every 0.10 seconds of game time
-
-
Bedingungen
-
(GroupPushBack1 is empty) Gleich False
-
-
Aktionen
-
Einheitengruppe - Pick every unit in GroupPushBack1 and do (Actions)
-
Schleifen - Aktionen
-
Set tmpPoint1 = (Position of (Picked unit))
-
Set tmpUnit1 = (Picked unit)
-
Custom script: set udg_Key3 = GetHandleId(udg_tmpUnit1)
-
Set tmpInt01 = (Load hashPushDur of Key3 from TheHashtable1)
-
Set tmpReal01 = (Load hashPushSpeedX of Key3 from TheHashtable1)
-
Set tmpReal02 = (Load hashPushSpeedY of Key3 from TheHashtable1)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
'IF'-Bedingungen
-
tmpInt01 Gleich 1
-
-
'THEN'-Aktionen
-
Einheitengruppe - Remove (Picked unit) from GroupPushBack1
-
-
'ELSE'-Aktionen
-
-
Set tmpInt01 = (tmpInt01 - 1)
-
Hashtabelle - Save tmpInt01 as hashPushDur of Key3 in TheHashtable1
-
Set tmpReal01 = (tmpReal01 + (X of tmpPoint1))
-
Set tmpReal02 = (tmpReal02 + (Y of tmpPoint1))
-
Custom script: call RemoveLocation(udg_tmpPoint1)
-
Set tmpPoint1 = (Point(tmpReal01, tmpReal02))
-
Einheit - Move (Picked unit) instantly to tmpPoint1
-
Custom script: call RemoveLocation(udg_tmpPoint1)
-
-
-
-
or
b) with local timers:
JASS:
// ----------------------------------------------------------------------------
//Pushback:
function pushback2 takes nothing returns nothing
// declaring and loading
local timer t=GetExpiredTimer()
local timer t2=CreateTimer()
local unit u
local real x
local real y
local location p
set u = LoadUnitHandle(udg_TheHashtable1, GetHandleId(t), 1)
set x = LoadReal(udg_TheHashtable1, GetHandleId(t), 2)
set y = LoadReal(udg_TheHashtable1, GetHandleId(t), 3)
set p = GetUnitLoc(u)
// operation
call SetUnitX(u,GetLocationX(p)+x)
call SetUnitY(u,GetLocationY(p)+y)
set x = x*0.95
set y = y*0.95
// new timer
if (Pow(Pow(x,2)+Pow(y,2),0.5) < 2.5) then
call PauseTimer(t2)
call DestroyTimer(t2)
set t2=null
else
call TimerStart(t2, 0.1, false, function pushback2)
call SaveUnitHandle(udg_TheHashtable1, GetHandleId(t2), 1, u)
call SaveReal( udg_TheHashtable1, GetHandleId(t2), 2, x )
call SaveReal( udg_TheHashtable1, GetHandleId(t2), 3, y )
endif
// clearing
call FlushChildHashtable( udg_TheHashtable1, GetHandleId(t) )
call PauseTimer(t)
call DestroyTimer(t)
call RemoveLocation(p)
set p=null
set t=null
set t2=null
set u=null
endfunction
function pushback1 takes unit u, real x, real y returns nothing
// x is the velocity on x-axis and y likewise on y axis. u is pushed unit.
local timer t=CreateTimer()
call TimerStart(t, 0.1, false, function pushback2)
call SaveUnitHandle(udg_TheHashtable1, GetHandleId(t), 1, u)
call SaveReal( udg_TheHashtable1, GetHandleId(t), 2, x )
call SaveReal( udg_TheHashtable1, GetHandleId(t), 3, y )
set t=null
endfunction
or is there a better way?
thanks in advance