Phix : nested structs

new topic     » topic index » view thread      » older message » newer message

Hallo,

I want to create an array of nested structs.

I came up with this (and experimented with it), and it seems to work.

But is this the right way to do it? It looks a little strange to me.

constant MAX=10 
 
 
public struct Vector2  
    atom x = 0   
    atom y = 0   
end struct 
 
public struct Camera2D   
    Vector2 offset 
    Vector2 target 
    atom rotation =10   
    atom zoom = 20      
end struct 
 
Camera2D camX  
 
 
sequence array=(repeat(0,MAX)) 
 
for i=1 to MAX do 
--Camera2D camX 
    array[i]=new(Camera2D) -- This is not enough 
    camX=array[i] 
    camX.offset=new(Vector2) -- i need also this 
    camX.target=new(Vector2) -- and this 
    camX.offset.x=i 
    camX.offset.y=camX.offset.x*i 
end for 
--?array[1].zoom --nope 
? "--" 
 
for i=1 to MAX do 
--Camera2D camX 
    camX=array[i] 
    ?camX.offset.y 
end for 
 
? "--" 
 
--?array[2].zoom 
camX=array[2] 
camX.offset.x=100 
?camX.offset.x 
 
camX=array[3] 
camX.offset.x=130 
?camX.offset.x   
 
camX=array[2] 
?camX.offset.x 
 
wait_key() 
new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu