I haven't been working with vJass for a while and I may have forgotten a thing or two...
Currently I'm trying to get my struct instances to work with a unit indexer.
I've done the following:
Now what I am trying to do is the following:
itterate through all struct instances (or at least return the instance with the right unit id) to find out if the instance contains the same unit id for a triggering unit.
I'm not sure if I'm doing this correctly but this is what I've got so far:
I want to make sure that when there is no struct instance with the same unit id, it will create a new struct instance for me.
Is this the right way to go about it? By checking if the returned struct instance is 0?
Because for some reason my respawn system will only respawn the unit once and doesn't work after that.
The function catchAddedUnitsActions will run whenever a new unit gets added to the map so... I figured I'm doing it wrong.
Currently I'm trying to get my struct instances to work with a unit indexer.
I've done the following:
JASS:
struct myStruct
unit u
player owningPlayer
integer unitType
real posX
real posY
real face
static integer array structIndex
static method create takes unit v returns thistype
local thistype this = thistype.allocate()
set structIndex[GetUnitId(v)] = this
set .u = v
set .unitType = GetUnitTypeId(v)
set .posX = GetUnitX(v)
set .posY = GetUnitY(v)
set .face = GetUnitFacing(v)
set .owningPlayer = GetOwningPlayer(v)
return this
endmethod
static method operator [] takes unit v returns thistype
return structIndex[GetUnitId(v)]
endmethod
Now what I am trying to do is the following:
itterate through all struct instances (or at least return the instance with the right unit id) to find out if the instance contains the same unit id for a triggering unit.
I'm not sure if I'm doing this correctly but this is what I've got so far:
JASS:
private function catchAddedUnitsActions takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer creepTypeIndex = checkUnitType(u)
local respawnUnit thisUnit = respawnUnit[u]
call BJDebugMsg(I2S(thisUnit))
if thisUnit == 0 then
if creepTypeIndex != 0 then
set thisUnit = respawnUnit.create(u, creepTypeIndex)
endif
endif
return FALSE
endfunction
I want to make sure that when there is no struct instance with the same unit id, it will create a new struct instance for me.
Is this the right way to go about it? By checking if the returned struct instance is 0?
Because for some reason my respawn system will only respawn the unit once and doesn't work after that.
The function catchAddedUnitsActions will run whenever a new unit gets added to the map so... I figured I'm doing it wrong.