What is wrong with this code

BlitzMax Forums/BlitzMax Beginners Area/What is wrong with this code

abdedf(Posted 2010) [#1]
I am trying to create an array of type "tile".


Graphics 800,600,0

Type tile
Field x:Int,y:Int
End Type

Global tiles:tile[]=New tile[100]

For i=0 To 99
tiles[i].x=i
tiles[i].y=i
Next

Repeat

DrawText(tiles[5].x,10,10)
Flip;Cls
Until MouseDown(1)


GfK(Posted 2010) [#2]
Global tiles:tile[100]



Ked(Posted 2010) [#3]
What Gfk said, then your loop should be:
For i=0 to 99
     tiles[i]=New tile
     tiles[i].x=i
     tiles[i].y=i
Next



GfK(Posted 2010) [#4]
Yep. Was just reinstalling Blitzmax to try that. :D


abdedf(Posted 2010) [#5]
Works now. Thanks for the quick replies.


Czar Flavius(Posted 2010) [#6]
When you create an object array, each element contains null to begin with.


Arabia(Posted 2010) [#7]
So this makes an array of type Tile if I understand correctly, which is something I want to use myself.

Is this the correct way (if that makes sense?) to use types? The only other time I've used them you just make NEW tiles as required and you can cycle through them (a linked list?)

I hope my question makes sense, I'll try and explain further if needed.


GfK(Posted 2010) [#8]
Is this the correct way (if that makes sense?) to use types? The only other time I've used them you just make NEW tiles as required and you can cycle through them (a linked list?)
There is no right or wrong way.

Depending on what you're trying to do, you can use arrays, lists, tmaps, globals, whatever works best.