- Joined
- Feb 23, 2008
- Messages
- 587
Questions
1. Is this how I declare a local and global struct, and a local array of structs and a global array of structs?
2.Array of structs cant have methods. Correct?
3.If I wanted something like in array of structs (Values, And methods) vJass doesn't currently support anything like it, or any other warcraft scripting languages.
Here is my sample Code I Made, To help me understand how to work with structs
1. Is this how I declare a local and global struct, and a local array of structs and a global array of structs?
2.Array of structs cant have methods. Correct?
3.If I wanted something like in array of structs (Values, And methods) vJass doesn't currently support anything like it, or any other warcraft scripting languages.
Here is my sample Code I Made, To help me understand how to work with structs
JASS:
function CreateLocalStruct takes nothing returns nothing
//Create Local Object and run Constructor
local Object myLocalObject = Object.create()
//Call Meathods
call myLocalObject.setX(100)
call myLocalObject.addFiveToX()
call DisplayTimedTextToForce( GetPlayersAll(), 30, I2S(myLocalObject.getX()) )
endfunction
function CreateGlobalStruct takes nothing returns nothing
//Create Global Object
globals
Object myGlobalObject
endglobals
//Call Constructor
call myGlobalObject.create()
//Call Meathods
call myGlobalObject.setX(100)
call myGlobalObject.addFiveToX()
call DisplayTimedTextToForce( GetPlayersAll(), 30, I2S(myGlobalObject.getX()) )
endfunction
function CreateLocalArrayOfStructs takes nothing returns nothing
//Create Array Of "ObjectPlusArray"
local ObjectPlusArray myOPA
//You cant have a constructor
//Access Variables Directly
//Meathod 1
set ObjectPlusArray[0].x = 5
//Meathod 2
set myOPA = ObjectPlusArray[0]
set myOPA.x = 5
//You Cant Call Meathods On Arrays Of Structs
endfunction
function CreateGlobalArrayOfStructs takes nothing returns nothing
//Create Array Of "ObjectPlusArray"
globals
ObjectPlusArray myGOPA
endglobals
//You cant have a constructor
//Access Variables Directly
//Meathod 1
set ObjectPlusArray[0].x = 5
//Meathod 2
set myGOPA = ObjectPlusArray[0]
set myGOPA.x = 5
//You Cant Call Meathods On Arrays Of Structs
endfunction
scope SetupGame initializer InitA
function InitA takes nothing returns nothing
call CreateLocalStruct()
call CreateGlobalStruct()
//It would be very un-wise To Have a local
//and global Array of the same type of struct
call CreateLocalArrayOfStructs()
call CreateGlobalArrayOfStructs()
endfunction
endscope
JASS:
library MyLibary
struct Object
//Varibles
integer x
//Constructor
static method create takes nothing returns thistype
local Object r = Object.allocate()
set r.x = 0
return r
endmethod
//Get
method getX takes nothing returns integer
return this.x
endmethod
//Set
method setX takes integer x returns nothing
set this.x = x
endmethod
//Action
method addFiveToX takes nothing returns nothing
set .x = .x + 5
endmethod
endstruct
struct ObjectPlusArray extends array
//Varibles
integer x
//You cant have a constructor
//You cant have methods
endstruct
endlibrary