Ah this tutorial ^^
Yep it really removes the variable from the existence
But it is absolutely NEEDED
<name> in your example is the name of the variable.
When you use <name>.<something> you access the member called <something> of the struct variable <name>
Members of a struct variable are variables (in my Point example it is x or y) but can also be methods.
What is a method ?
A method is a function specific to a struct.
There is two different types of method :
- Static method -> They work EXACTLY THE SAME AS FUNCTIONS.
Example :
struct Point
real x
real y
//I create my own create method for the variable type Point
static method create takes nothing returns Point
local Point p = Point.allocate() //I create a Point with uninitialized coordinates
set p.x = 42
set p.y = 27
return p
endmethod
endstruct
//In random func
function RandomFunc takes nothing returns nothing
local Point p = Point.create() //To call static method : <TypeName>.<methodName>
call BJDebugMsg(R2S(p.x)) //This will display 42
call p.destroy()
endfunction
Basically JASSHelper generates create/allocate (it is the same) and destroy/deallocate (same there).
But you can create more.
- Non static methods : Those methods takes automatically a struct variable as parameters.
Example :
struct Point
real x
real y
method troll takes nothing returns nothing
set this.x = 42 //To refer to the implicit parameters use this
set this.y = 27
//No need to return -> The changes are automatic.
endmethod
endstruct
//In random func :
function RandomFunc takes nothing returns nothing
local Point p = Point.create()
call p.troll() //To call non static methods : <nameOfTheVar>.<nameOfMethod>
call BJDebugMsg(p.x) //This will display 42
endfunction
Now some tricks :
- When you're inside the struct, you can refer to the name of the struct by using thistype :
struct OmgMyNameIsTooLongItWillBeSoBoringToTypeItEverywhereXD
real x
real y
static method create takes nothing returns thistype
local thistype this = thistype.allocate()
...
return this
endmethod
endstruct
Here I use this for nothing, it is just the name of the variable.
But it is syntax highlighted