Arrays of types?
Blitz3D Forums/Blitz3D Beginners Area/Arrays of types?
| ||
Hi! I'm just getting back into Blitz after surviving my first and second years of university, including the University Semester from Hell (which I've just survived)... Anyway, it appears that I've forgotten most of what I had learned before I took my break from Blitz, and that includes how to make arrays of types. So, say I want 100 enemies, all with their own X and Y variables. I'd create a type: Type TYPE_Enemy Field X_Pos Field Y_Pos End Type ...but then how would I make an array that uses the type? I want to be able to call it like this: Enemy(35)\X_Pos = 20 Enemy(27)\Y_Pos = 250 Is this possible? If so, how can you do this? |
| ||
What you have is fine... - if your asking how you create an array of types..you simply do the following... Dim Enemies.Enemy(100) ;create 100 enemy references Now you for next through the indices of the array + Enemies(n)=new enemy ;assign new instance simple enough? |
| ||
I don't think you can use arrays like that in a type collection. I think you need to use a blitz array for it. dim Enemies.Enemy[100]; use square brackets downfall of this is i think blitz arrays are a bit slower (not by that much) and can only have one dimention. |
| ||
If you need an array within a custom type..sure you need to use square brackets + the dim command isnt needed.. however - if all you want is an array of custom type references..the first method will work.. - i think your getting confused ross? anyway... |
| ||
Thanks Defoc8. Your first post is the answer I wanted. I wanted to use an array with a type, not put an array within a type. |
| ||
Yeah, sorry for the confusion, i apologise :) |