Arrays. Assigning a value.

BlitzMax Forums/BlitzMax Beginners Area/Arrays. Assigning a value.

Amon_old(Posted 2005) [#1]
For Local x:Int = 0 To 9
	
	For Local y:Int = 0 To 9
	
		array:Int[x,y] = 0
		
	Next
	
Next

array:Int[2,6] = 1


I have a for/next loop which fills my array with 0's.

This line here "array:Int[2,6] = 1" should assign the value 1 to that position in the array. NO!


tonyg(Posted 2005) [#2]
You still have to define your array...
local/global array:int[10,10]


Amon_old(Posted 2005) [#3]
Yep, already done that.

Just checking if it does assign the value 1 to that position in the array which it does.

Thanks :)


skn3(Posted 2005) [#4]
Also as with any data type in blitz, you only need to define it when you create it.

So you dont need to do
array:int[x,y] = 10
array%[x,y] = 10


Simply
array[x,y] = 10



xlsior(Posted 2005) [#5]
Something else to check for: I don't know how you define your array since you didn't include that part of your pogram in the code above, but:

array:int[6,6]

will create an array that holds 6 cells to store information -- however, these will be addressed at 0,1,2,3,4,5... Note that these start at 0, and end at 5--- '6' itself does not exist.

Also, when you turn on Debug mode, does your program actually generate an error? e.g. "unhandled exception: attempt to index array element beyond array length"?

If you don't turn on debug, writing outside of the defined array will NOT result in an error, but it will end up writing in random memory locations -- which are not part of the array, and can change at any time, so trying to read back that non-existent slot can result in random different data being pulled if it changed in the mean time.


Amon_old(Posted 2005) [#6]
Thanks guys. I have it working now.

:)