decored
New Member
- Reaction score
- 3
What are the various functions of struct like create() etc
struct Meh
static method create takes nothing returns thistype // You can also use 'Meh' here, but thistype is the same thing basically <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue :p" loading="lazy" data-shortname=":p" />
local thistype this = thistype.allocate() // It's here we actually "create" the struct, and again you can use 'Meh' instead of 'thistype'
//and you can also use any other letters than 'this' but if you use 'this' you will not need to write stuff like call data.destroy()
//(In this case, 'data' is what was used instead of 'this' <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink ;)" loading="lazy" data-shortname=";)" />) you can just write call destroy() and it will destroy the struct <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />
return this // Here we return the newly created struct to the "system" <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />
endmethod
endstruct
struct Meh
location loc
static method create takes unit u returns thistype
local thistype this = thistype.allocate()
set loc = GetUnitLoc( u ) // We will want to clean this up after the struct is
//destroyed (Or is about to be) and that's where the 'onDestroy' method comes in <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink ;)" loading="lazy" data-shortname=";)" />
call destroy() // This will now destroy this struct, and also call the 'onDestroy' method <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />
return this
endmethod
method onDestroy takes nothing returns nothing
call RemoveLocation( loc) // And here we clean up the leak <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin :D" loading="lazy" data-shortname=":D" />
endmethod
endstruct
struct Meh
location loc
static method create takes unit u returns thistype
local thistype this = thistype.allocate()
set loc = GetUnitLoc( u )
return this
endmethod
method onDestroy takes nothing returns nothing
call RemoveLocation( loc)
endmethod
static method Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local thistype this = thistype.create( u )
set u = null
endmethod
static method Conditions takes nothing returns boolean
return GetSpellAbilityId() == 039;test039;
endmethod
static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( t, Condition( function Conditions ) )
call TriggerAddAction( t, function Actions )
endmethod
endstruct