Hi , I was making a system for my map and got some troubles with static variables inside structs (this is because i have no idea how does it works)
seems like player static variable ".p" just can save the last value assigned ,plz can someone tell me how the static variables works?
JASS:
//sorry, I couldn't paste all my code because it was too long, but this is
//what is happening
library test initializer init
struct myStruct
private static player p
private static real mainX
private static real mainY
private timer t
static method something takes nothing returns nothing
if .p == GetLocalPlayer() then
call PanCameraToTimed(.mainX ,.mainY,0)
endif
endmethod
method forCamera takes nothing returns nothing
set .t = CreateTimer()
call TimerStart(.t,0.05,true, function thistype.something)
endmethod
static method onCreate takes player p , real x , real y returns thistype
local myStruct this = myStruct.allocate()
set .p = p
set .mainX = x
set .mainY = y
return this
endmethod
endstruct
// and my call
private function init takes nothing returns nothing
local myStruct StructA = myStruct.onCreate(Player(0),100,300)//for this player works fine forcing the camera ,while there aren't more structs(instances) ,just StructA is created
local myStruct StructB = myStruct.onCreate(Player(1),100,300)//when i try to get another instance for blue player ,camera doesn't works for red player
local myStruct StructC = myStruct.onCreate(Player(2),100,300)//when i try to get another instance for teal player ,camera doesn't works for red player and blue player
endfunction
endlibrary
seems like player static variable ".p" just can save the last value assigned ,plz can someone tell me how the static variables works?