array of usertype

BlitzMax Forums/BlitzMax Beginners Area/array of usertype

djdee(Posted 2006) [#1]
example:
----------------------------
type tile
bla bla bla
end type

local x = 10
local y = 10
Global map:tile[]
map:tile = New tile[x, y]
----------------------------

result "unable to convert from 'tile array' to 'tile array'.. So how do you do it ?? I looked at the example in the "manual" but there was only an example of integer array.


Perturbatio(Posted 2006) [#2]
Local Width:Int
Local Height:Int
Global map:tile[Width, Height]
For Local x:int = 0 to Width-1
   For Local y:Int = 0 to Height -1
      map[x,y] = new tile
   Next
Next



klepto2(Posted 2006) [#3]
Or if you want to init it blank, then simply do this

Global map:tile[,] <--- look at the comata


djdee(Posted 2006) [#4]
Here is an example of what im trying to do.. but i still get errors......
--------------------------------------------------------


Type mytype_1
Field my_field%
End Type

Type mytype_2
Field array:mytype_1[,]

Method New()
array = New mytype_1[2,2]
End Method
End Type

my_instance:mytype_2 = New mytype_2

my_instance.array[1,1].my_field% = 1
my_instance.array[1,2].my_field% = 2
my_instance.array[2,1].my_field% = 3
my_instance.array[2,2].my_field% = 4


djdee(Posted 2006) [#5]
I used the example from here: http://www.blitzwiki.org/index.php/Arrays#Arrays_in_Types
but i still get problems.... Anybody know whats up ???


taxlerendiosk(Posted 2006) [#6]
Type mytype_1
	Field my_field%
End Type

Type mytype_2
	Field array:mytype_1[,]

	Method New()
		array = New mytype_1[2,2]
		For Local i:Int = 0 To 1
			For Local j:Int = 0 To 1
				array[i,j] = New mytype_1
			Next
		Next
	End Method
End Type

my_instance:mytype_2 = New mytype_2

my_instance.array[0,0].my_field% = 1
my_instance.array[0,1].my_field% = 2
my_instance.array[1,0].my_field% = 3
my_instance.array[1,1].my_field% = 4 


Creating a new array of objects really only creates an array of "empty slots" - you still have to actually create objects to put "into" them, before you can refer to their fields etc.

Also, if you create an array of N objects, they are numbered 0 to N-1. For example if you create an array of size 3 you need to refer to them as array[0] array[1] array[2], not array[1] array[2] array[3].


djdee(Posted 2006) [#7]
THANX a bunch !