What is wrong with this code
BlitzMax Forums/BlitzMax Beginners Area/What is wrong with this code
| ||
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) |
| ||
Global tiles:tile[100] |
| ||
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 |
| ||
Yep. Was just reinstalling Blitzmax to try that. :D |
| ||
Works now. Thanks for the quick replies. |
| ||
When you create an object array, each element contains null to begin with. |
| ||
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. |
| ||
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. |