what are the periods used for in that statement?
struct StructName
integer member
endstruct
//And another one, for fun ^_^
struct SomethingElse
integer anotherMember
endstruct
function Test takes nothing returns nothing
local StructName structVar = StructName.create ()
local SomethingElse data = SomethingElse.create ()
//Struct member must be prefixed by variablename. like so
set structVar.member = 15
set data.anotherMember = 72
endfunction
EDIT. oh ye, wait sec i post more code.
EDIT2. Here is some fast made example how to attach some Data to some Hero, it might be usefull in some map where you have some Heroes...
JASS:struct Velocity real x real y real z endstruct struct Color integer red = 255 integer green = 255 integer blue = 255 integer alpha = 255 endstruct struct Heroes string n = "nuthing" Color C Velocity V endstruct function F takes nothing returns nothing local Heroes H = Heroes.create() local unit somehero // some brave hero unit set H.C = Color.create() set H.V = Velocity.create() // set H.V.x = GetRandomReal(-100,100) // call SetUnitUserData(somehero,H) endfunction
First: For anyone else reading, everything except the last post is over a year old. No jumping on TriggerHappy for not knowing what structs are.
That code is bad practise, it uses UnitUserData directly.
For attaching to heroes (or any units) use AIDS or PUI.
struct location
private real x
private real y
static method create takes real x, real y returns thistype
thistype loc = .allocate()
set loc.x = x
set loc.y = y
return loc
endmethod
method move takes real x, real y returns nothing
set this.x = x
set this.y = y
endmethod
method getX takes nothing returns real
return this.x
endmethod
method getY takes nothing returns real
return this.y
endmethod
endstruct
function Location takes real x, real y returns location
return location.create(x, y)
endfunction
function MoveLocation takes location loc, real x, real y returns nothing
call loc.move(x, y)
endfunction
function GetLocationX takes location loc returns real
return loc.getX()
endfunction
function GetLocationY takes location loc returns real
return loc.getY()
endfunction
function RemoveLocation takes location loc returns nothing
call loc.destroy()
endfunction
globals
location previousLoc
endglobals
//We'll assume it has been given an initial value of some sort...
function SomeTriggerActions takes nothing returns nothing
call CreateUnit( Player(GetTriggerPlayer()), GetLocationX(previousLoc), GetLocationY(previousLoc), face)
call MoveLocation(previousLoc, x, y)
endfunction
struct Vector3
real x
real y
real z
static method create takes real x, real y, real z returns thistype
local thistype v3 = .allocate()
set v3.x = x
set v3.y = y
set v3.z = z
return v3
endmethod
method move takes real x, real y, real z returns nothing
set this.x = x
set this.y = y
set this.z = z
endmethod
endstruct
function SomeTriggerActions takes nothing returns nothing
local unit u = GetTriggerUnit()
local Vector3 v3 = Vector3.create(GetUnitX(u), GetUnitY(u), GetUnitZ(u)
call BJDebugMsg( "X = " + R2S(v3.x) )
call BJDebugMsg( "Y = " + R2S(v3.y) )
call BJDebugMsg( "Z = " + R2S(v3.z) )
call v3.destroy()
endfunction
function GetUnitZ takes unit u returns real
call MoveLocation( dummyLoc, GetUnitX(u), GetUnitY(u) )
return GetLocationZ(dummyLoc) + GetUnitFlyHeight(u)
endfunction