Okay so I made this script with the intention of using it for something:
The problem is: how can I do this correctly?
EDIT: I think I need to use a heap allocator, but I'm not sure...
Should I implement Binary Heap instead? http://www.hiveworkshop.com/forums/jass-resources-412/snippet-binary-heap-199353/ (tried this but it gives me an error, check my last post)
I'm currently using it like this:
JASS:
struct myStruct extends array
private integer id
implement Alloc
static method operator [] takes integer index returns thistype
local thistype this = thistype(index).allocate()
.id = index
return this
endmethod
private static method doSomething takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer uId = GetHandleId(u) - 0x100000
local thistype myNewInstance = thistype[uId]
call BJDebugMsg(I2S(thistype(uId).id)) //prints 0 because of stack allocation from Alloc I suppose?
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_DESELECTED, null)
set i = i + 1
exitwhen i == bj_MAX_PLAYER_SLOTS
endloop
call TriggerAddCondition(t, Condition(function thistype.doSomething))
set t = null
endmethod
endstruct
The problem is: how can I do this correctly?
EDIT: I think I need to use a heap allocator, but I'm not sure...
Should I implement Binary Heap instead? http://www.hiveworkshop.com/forums/jass-resources-412/snippet-binary-heap-199353/ (tried this but it gives me an error, check my last post)
I'm currently using it like this:
JASS:
implement BinaryHeap
static method operator [] takes integer index returns thistype
local thistype this = thistype.allocate(index)
.id = index
return this
endmethod
Last edited: