- Joined
- Feb 8, 2015
- Messages
- 124
Recently getting into lua (after just getting into JASS...) and while the use of local variables makes a lot of MUI easier, I'm not certain how to deal with delayed/repeating actions for multiple instances.
The spell I'm making is fairly straight forward. Mark a target area and continually deal damage through it (like a Blizzard, but without the channel)... There's also a dummy unit involved, but that part is simpler.
Now, in JASS I would've done something like this:
And the periodically (recursively) run function is
That's all very well and good for JASS and global hashtables (from the GUI variable editor), but that's not how you're supposed to do things in Lua, as I understand it.
My queston (perhaps too broad for this forum) then; how am I supposed to do this in lua?
Using global variables seems out of the question - since I want to allow multiple simultaneous instances, each counting waves separately and "remembering" the right caster. I take it this is a place to use lua tables? But I'm not experienced with it, as I've only coded in Python, C++ and JASS.
The spell I'm making is fairly straight forward. Mark a target area and continually deal damage through it (like a Blizzard, but without the channel)... There's also a dummy unit involved, but that part is simpler.
Now, in JASS I would've done something like this:
JASS:
function Trig_Nebula_cast_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local timer t = CreateTimer()
local integer id = GetHandleId(t)
local real area = 200 // placeholder value for readability
local real damage = 100 // placeholder value for readability
local integer wcount=1
local real x = GetSpellTargetX()
local real y = GetSpellTargetY()
call SaveUnitHandle(udg_Spell_Table, id, 1, u)
call SaveReal(udg_Spell_Table, id, 2, damage)
call SaveReal(udg_Spell_Table, id, 3, area)
call SaveReal(udg_Spell_Table, id, 4, x)
call SaveReal(udg_Spell_Table, id, 5, y)
call SaveInteger(udg_Spell_Table, id, 6, count)
call TimerStart(t, 1.0, false, function PeriodicDamage)
set t = null
set u = null
endfunction
JASS:
function PeriodicDamage takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local unit u = LoadUnitHandle(udg_Spell_Table, id, 1)
local real dmg = LoadReal(udg_Spell_Table, id, 2)
local real area = LoadReal(udg_Spell_Table, id, 3)
local real x = LoadReal(udg_Spell_Table, id, 4)
local real y = LoadReal(udg_Spell_Table, id, 5)
local integer count = LoadInteger(udg_Spell_Table, id, 6)
local group ug = CreateGroup()
local unit pu
if wcount <= 6 then
call GroupEnumUnitsInRange(ug, x, y, area, null)
loop
set pu = FirstOfGroup(ug)
exitwhen (pickedu == null)
if IsUnitEnemy(pu, GetOwningPlayer(u)) then
call UnitDamageTarget(u, pu, dmg, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
endif
call GroupRemoveUnit(ug, pu)
endloop
call DestroyEffect(AddSpecialEffect("SpecialEffect\\Something.mdl", x , y))
call SaveInteger(udg_Spell_Table, id, 6, count+1)
call TimerStart(t, 1.0, false, function PeriodicDamage)
else
//cleanup
call PauseTimer(t)
call DestroyTimer(t)
call FlushChildHashtable(udg_Spell_Table, id)
endif
call DestroyGroup(ug)
set ug = null
set pickedu = null
set u = null
set t = null
endfunction
That's all very well and good for JASS and global hashtables (from the GUI variable editor), but that's not how you're supposed to do things in Lua, as I understand it.
My queston (perhaps too broad for this forum) then; how am I supposed to do this in lua?
Using global variables seems out of the question - since I want to allow multiple simultaneous instances, each counting waves separately and "remembering" the right caster. I take it this is a place to use lua tables? But I'm not experienced with it, as I've only coded in Python, C++ and JASS.
























