can someone show me how put an array in an array,
1.creation of the arrays
2.filling the arrays
3.accessing the arrays
and also a type within a type.
Id like to have an array of 3 tanks with an array of 4 gun turrets each
I don't know if this will answer your question: you can have multidimensional arrays.
eg:
dim x(3,4)
will give you 3*4 turrets, you can then access it like this:
x(tank,1)=100
note: you can also use Zero as index, so dim x(3,4) will actually give you 4*5 array indexes (0 to 3 * 0 to 4).
To acces the fields of a chessboard you would do something like:
dim chess(7,7)
for y=0 to 7
for x=0 to 7
chess(x,y)=rand(whatever)
next
next
For types it's better some types experts will answer this.
Type tank
;other fields
Field gun.gun[4] ;created here
End Type
Type gun
;other fields
Field power ;good dun parameter. wither this or gun type
End Type
Global tankarray.tank[3]
For a=1 To 3
tankarray[a]=createtank.tank()
Next
Print gunpower(tankarray[1],1)
Function createtank.tank()
t.tank=New tank
For a=1 To 4
t\gun.gun[a]=New gun ;creation
t\gun.gun[a]\power=Rand(1,5) ;modification
Next
Return t.tank
End Function
Function gunpower(t.tank,index)
Return t\gun[index]\power ;access
End Function
The way i think of arrays, is the first dimention is the object (comparing to types). The next dimention is the properties. Works great and saves me from using types. I like types but i think arrays are easier to access, in regards selecting a particular 'object'. Sorry if it Off Topic, but i just thought id say that :)
I dont understand your code B.B. so Ill try multidimensional arrays.
Finally, one who use arrays like I do. If people learned about the usefullness of arrays from the start, then the world would be a better place (and a lot of dumb questions would be spared)
Using types, and then comparing types to arrays can be better than just using either :)