~GaLs~
† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
- Reaction score
- 180
What is .allocate()?
How do we use it?
How do we use it?
struct r
static method create takes nothing returns r
return r.allocate()
endmethod
endstruct
Now that doesn't happen as we have a new create method inside our structure, so we have to create the structure by ourselves (not fully of course). .allocate() method creates us a unique INTEGER, which nothing else uses.When a struct does not have an specific create method declared, jasshelper will use allocate directly when .create is called.
globals //pasted to show struct-generated globals
integer si__tfx_F=0
integer si__tfx_I=0
integer array si__tfx_V
effect array s__tfx_fx
endglobals
//Generated allocator of tfx
function s__tfx__allocate takes nothing returns integer
local integer this=si__tfx_F
if (this!=0) then
set si__tfx_F=si__tfx_V[this]
else
set si__tfx_I=si__tfx_I+1
set this=si__tfx_I
endif
if (this>8190) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1000.,"Unable to allocate id for an object of type: tfx")
return 0
endif
set si__tfx_V[this]=-1
return this
endfunction
//Generated destructor of tfx
function sc__tfx_destroy takes integer this returns nothing
if this==null then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1000.,"Attempt to destroy a null struct of type: tfx")
return
elseif (si__tfx_V[this]!=-1) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1000.,"Double free of type: tfx")
return
endif
set f__arg_this=this
call TriggerEvaluate(st__tfx_onDestroy)
set si__tfx_V[this]=si__tfx_F
set si__tfx_F=this
endfunction
That's what he said. And what would you even do with it x)You cannot override it
globals
ourStruct array ourStruct_ar
integer totalStructs = 0
endglobals
struct ourStruct
string value
static method create takes nothing returns ourStruct
return ourStruct.allocate()
endmethod
endstruct
function createNewStructure takes nothing returns nothing
local ourStruct data = ourStruct.create()
local integer index = 0
set data.value = "Value of this struct is: "+I2S(GetRandomInt(0, 999))
set ourStruct_ar[totalStructs] = data
set totalStructs = totalStructs + 1
loop
exitwhen (index == totalStructs)
set ourStruct_ar[index] = 0
set index = index + 1
endloop
set index = 0
loop
exitwhen (index == totalStructs)
call BJDebugMsg(data.value)
set index = index + 1
endloop
endfunction