- Joined
- Jan 3, 2010
- Messages
- 359
i just saw some people create their JASS trigger with method, not with function ...
what's their different ???
what's their different ???
Methods are functions associated with an instance of a struct.
Static methods are functions associated with a struct.
These are strictly vJass features, meaning if you don't use vJass then you cannot use them.
They are compiled to functions anyways, so there's technically no difference.
Location(x, y)
vector.createTerrainPoint(x, y)
.GetLocationX(loc)
becomes vec.x
.GetLocationY(loc)
becomes vec.y
.GetLocationZ(loc)
becomes vec.z
.MoveLocation(loc, x, y)
becomes: vec.getTerrainPoint(x, y)
RemoveLocation(loc)
becomes: vec.destroy()
struct RocketShip
endstruct
struct RocketShip
real MaxSpeed
real CurrentSpeed
real Acceleration
integer Model
etc..
endstruct
local RocketShip Ship = RocketShip.Allocate()
set Ship.Maxspeed = 10
struct ship
real x
real y
endstruct
function foo takes ship p returns nothing
set p.x = 10.00
set p.y = 10.00
endfunction
function bar takes nothing returns nothing
local ship p = ship.create()
call foo(p)
call p.destroy()
endfunction
JASS:struct ship real x real y endstruct function foo takes ship p returns nothing set p.x = 10.00 set p.y = 10.00 endfunction function bar takes nothing returns nothing local ship p = ship.create() call foo(p) call p.destroy() endfunction
method operator lol takes nothing returns nothing
struct foo
private real x = 0
method operator X takes nothing returns real
return x
endmethod
method operator X= takes real newX returns nothing
set x = newX
call BJDebugMsg(R2S(newX))
endmethod
endstruct
function bar takes nothing returns nothing
local foo test = foo.create()
set test.X = test.X + 10 //Would pop out 10 on the screen
call test.destroy()
endfunction
set x= GetWidgetX(this.unit)
set y= GetWidgetY(this.unit)
set z= GetUnitFlyHeight(this.unit)
//and in another method:
set x= GetWidgetX(this.unit)
set y= GetWidgetY(this.unit)
set z= GetUnitFlyHeight(this.unit)
//and in another method:
local vector v = vector.create(GetWidgetX(this.unit), GetWidgetY(this.unit), GetUnitFlyHeight(this.unit))
method operator getx takes nothing returns real
return GetWidgetX(this.unit)
endmethod
method operator gety takes nothing returns real
return GetWidgetY(this.unit)
endmethod
method operator getz takes nothing returns real
return GetUnitFlyHeight(this.unit)
endmethod
set x = getx
set y = gety
set z = getz
//and in another method:
set x = getx
set y = gety
set z = getz
//and in another method
local vector v = vector.create(getx, gety, getz)