whats wrong with this

BlitzMax Forums/BlitzMax Beginners Area/whats wrong with this

RifRaf(Posted 2005) [#1]
Ok not alot of time to mess with bmax atm, but was wanting to try somthing.. why o why isnt this drawing the poly

Type trimodel
Field tri#[5]
Field groupname$
Field parent
End Type
Global trimodel_list:TList=New TList


t:trimodel=New trimodel
trimodel_list.AddLast t
t.tri[0]=0.0
t.tri[1]=0.0
t.tri[2]=100.0
t.tri[3]=100.0
t.tri[4]=0.0
t.tri[5]=100.0
t.groupname$="mypoly"

Graphics 640,480
While Not KeyHit(KEY_ESCAPE)
Cls
SetColor 255,255,255
DrawPoly t.tri
DrawText t.groupname$,20,20
Flip
Wend


Shambler(Posted 2005) [#2]
At first glance you have an array of [5] which is [0][1][2][3][4] but you are tying to access [5] aswell which doesn't exist so

field t#[6]



RifRaf(Posted 2005) [#3]
edit.

odd. it works great outside of debug mode, in fact all array indexes 0,1,2,3,4,5 all have the values i put in them.. inside debug mode though i do get an out of bounds error and must use a array size of 7 or better

thanks


Shambler(Posted 2005) [#4]
An array in max is an area of memory set aside to store some variables.

The data is stored at an address in memory ( lets call this 'address') and then you access each element by using an offset.

The first piece of data is stored at 'address' so the offset is zero.

An array of 5 elements are then accessed by

address+0
address+1
address+2
address+3
address+4

You are trying to access 6 elements so max should be giving you an array out of bounds error, is debug on?

Look here http://www.blitzwiki.org/index.php/Arrays