simple structure question

BlitzMax Forums/BlitzMax Beginners Area/simple structure question

Akat(Posted 2005) [#1]
im following NeHe tutorial along these days... it run smoothly until lesson 8... when it come to lesson 9, the C code using structure like this:

typedef struct
{
int r, g, b;
GLfloat dist;
GLfloat angle;
}
stars;
stars star[num];

in blitzmax, i do this:

type stars
field r,g,b
field dist#
field angle#
endtype

local star:stars[num] = new stars

i can't compile it... arghh... im suck at types man
how to create new array types then?? i dont even know am i asking the rite question..


Dreamora(Posted 2005) [#2]
local star:stars[] = new stars[num]


Akat(Posted 2005) [#3]
o really... is that simple... *sigh*... im really2 suck then... thanks a lot man...


insomnia(Posted 2006) [#4]
How do you access this array?
local star:stars[] = new stars[num]
e.g: star[3].r = 10 gives an error...

How I can make an array like this but with more dimensions?!


Dreamora(Posted 2006) [#5]
new stars[num] does only initialize the array. it does not create any object.
You have to create the objects first through

for local i:int = 0 to num-1
star[i] = new stars
next


For questions on array: the help explains how multi dimensional arrays work with a nice example :)

EDIT: fixed an error in my text.


insomnia(Posted 2006) [#6]
Thanks for your help!

If anybody else need an answer to this question:
How to use a two dimension array with a type as element:

Strict
Const num:Byte = 10

Type stars
	Field r,g,b
EndType
Global star:stars[,]
star = New stars[num,num]

For Local i:Byte = 0 to num-1
	For Local j:Byte = 0 to num-1
		star[i,j] = New stars
	Next
Next

star[5,2].r = 100
Print star[5,2].r