Arrays & Objects

BlitzMax Forums/BlitzMax Beginners Area/Arrays & Objects

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?

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

If you program on OO level, check out the linkedlist module. you will find many usefull methods that might give you what you want :)

Thanks Cajun,
That would be my problem :)

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

Thanks