Arrays & Objects

BlitzMax Forums/BlitzMax Beginners Area/Arrays & Objects

KrayzBlu(Posted 2005) [#1]
Hi all, new to Blitz

I've been looking at the Tlist stuff at it seems pretty cool, but what do I have to do if I want to acess a certain object by an array index?

I've tried making an array of Objects:

Global orbiterarray:Orbiter[]

and then putting the objects into that:

orbiterarray[0] = s1 ' s1 + s2 = premade objects
orbiterarray[1] = s2

But when I try to access any value from that object my program crashes.

Print orbiterarray[0].name ' is a string, makes program crash

Any help?


Cajun17(Posted 2005) [#2]
You're accessing it correctly at the end, but did you allocate any memory for the array or just declare it? If I'm not helping post the actual code.

Global orbiterarray:Orbiter[] 'declare the array

orbiterarray=new Orbiter[2] 'allocate memory for 2 objects

orbiterarray[0]=s1 'should work
orbiterarray[1]=s2 'should also work

print orbiterarray[0].name 'correct accessing of elemnt

orbiterarray=orbiterarray[..20] 'resize the array to 20 elements long keeping the current contents


Dreamora(Posted 2005) [#3]
If you program on OO level, check out the linkedlist module. you will find many usefull methods that might give you what you want :)


KrayzBlu(Posted 2005) [#4]
Thanks Cajun,
That would be my problem :)

Dreamora that stuff looks cool, I'll be taking a look at that.

Thanks