If you want to know how to use "structs" in vanilla WE - there is a way.
Here is an example struct I made (it's in the map's header, since I made it in the WE):
and an example usage:
In vJASS, with a real struct, this would look like:
And the example trigger would've been almost the same
Do have in mind that this way of doing things isn't exactly the way structs are doing things.
I think real structs also have a boolean array, that is checking if a struct index is used or not, and prevents functions to use them if they aren't created (I haven't really tested it, but it'd be logical if they do). And real structs go from 1 to 8190, and then back to the 1-st free one (I'm not sure if they are going backwards or forward after reaching 8190, and not sure if they aren't using a loop to go to the 1-st unused index), anyways... the method I'm using is kind a good enough for imitating structs
This is for people using the vanilla WE, the ones using JNGP can just use normal structs
Oh, and 1 more example how to set the structs values after creating it:
Here is an example struct I made (it's in the map's header, since I made it in the WE):
JASS:
// struct location
function create_location takes real x, real y returns integer
local integer this = udg_struct_location
if this == 0 then
set this = udg_struct_location_free[0] + 1
set udg_struct_location_free[0] = this
else
set udg_struct_location = udg_struct_location_free[this]
endif
set udg_struct_location_free[this] = - 1
if udg_struct_location <= 8190 then
set udg_struct_location_x[this] = x
set udg_struct_location_y[this] = y
return this
endif
return 8191
endfunction
function destroy_location takes integer this returns nothing
if udg_struct_location_free[this] == -1 then
set udg_struct_location_free[this] = udg_struct_location
set udg_struct_location = this
endif
endfunction
function move_location takes unit u, integer this returns nothing
if udg_stuct_location_free[this] == -1 then
call SetUnitX(u, udg_struct_location_x[this])
call SetUnitY(u, udg_struct_location_y[this])
endif
endfunction
// endstruct
and an example usage:
JASS:
function Trig_Test_Function_Actions takes nothing returns boolean
local real x = GetRandomReal(GetRectMinX(bj_mapInitialPlayableArea), GetRectMaxX(bj_mapInitialPlayableArea))
local real y = GetRandomReal(GetRectMinY(bj_mapInitialPlayableArea), GetRectMaxY(bj_mapInitialPlayableArea))
local integer loc = create_location(x,y)
call move_location(gg_unit_hfoo_0001, loc)
call destroy_location(loc)
return false
endfunction
//===========================================================================
function InitTrig_Test_Function takes nothing returns nothing
set gg_trg_Test_Function = CreateTrigger( )
call TriggerRegisterPlayerEventEndCinematic( gg_trg_Test_Function, Player(0) )
call TriggerAddCondition( gg_trg_Test_Function, Condition(function Trig_Test_Function_Actions) )
endfunction
In vJASS, with a real struct, this would look like:
JASS:
struct Point
real x
real y
static method create takes real x, real y returns Point
local Point loc = Point.allocate()
set loc.x = x
set loc.y = y
return loc
endfunction
// no "onDestroy" method, since nothing special is done.
method move takes unit u returns nothing
call SetUnitX(u, this.x)
call SetUnitY(u, this.y)
endmethod
endstruct
And the example trigger would've been almost the same
Do have in mind that this way of doing things isn't exactly the way structs are doing things.
I think real structs also have a boolean array, that is checking if a struct index is used or not, and prevents functions to use them if they aren't created (I haven't really tested it, but it'd be logical if they do). And real structs go from 1 to 8190, and then back to the 1-st free one (I'm not sure if they are going backwards or forward after reaching 8190, and not sure if they aren't using a loop to go to the 1-st unused index), anyways... the method I'm using is kind a good enough for imitating structs
This is for people using the vanilla WE, the ones using JNGP can just use normal structs
Oh, and 1 more example how to set the structs values after creating it:
JASS:
function Trig_Test_Function_Actions takes nothing returns boolean
local integer loc = create_location(0,0)
set udg_struct_location_x[loc] = GetRandomReal(GetRectMinX(bj_mapInitialPlayableArea), GetRectMaxX(bj_mapInitialPlayableArea))
set udg_struct_location_y[loc] = GetRandomReal(GetRectMinY(bj_mapInitialPlayableArea), GetRectMaxY(bj_mapInitialPlayableArea))
call move_location(gg_unit_hfoo_0001, loc)
call destroy_location(loc)
return false
endfunction
Last edited: