How do i make multiple arrays?

BlitzPlus Forums/BlitzPlus Programming/How do i make multiple arrays?

Nitsua_Revaew(Posted 2012) [#1]
I have recently tried blitzplus, and am having a great time. I do, however, have a small problem. I use a two dimensional array as the tiled background of my game, and i read the array for the coordinates to find each individual coordinate. When it finds it out it checks what number it is and gives it a tile image. However, when i try to make a different array with a different name, it gives me an error. Please help!


Zethrax(Posted 2012) [#2]
As far as I'm aware (assuming BlitzPlus behaves like Blitz3D with arrays) you can't create standard arrays (the ones that use the round bracket syntax) on the fly. You create them once and can then Dim them again to clear and re-dimension them, but that's pretty much it. Note that there's no restriction on how many you can initially create.

Blitz arrays (the ones that use the square bracket syntax) can appear as a field in custom type objects. You can create custom type objects on the fly, so you can basically create Blitz arrays on the fly. They are one dimensional though, and you can't re-dimension (re-size) them. A bit of math can give you as many dimensions as you need with them. These types of arrays are also known as static arrays.

Links:-
http://www.blitzbasic.com/bpdocs/command.php?name=Dim&ref=2d_cat (note that this doesn't mention Blitz arrays)
http://www.blitzbasic.com/b3ddocs/command.php?name=Dim&ref=2d_cat (this mentions Blitz arrays)

eg (Blitz arrays).
Type T_my_array_object
Field my_array[ 99 ] ; An array field with 100 elements.
End Type

my_array_pointer.T_my_array_object = New T_my_array_object

my_array_pointer\my_array[ 0 ] = 123

Last edited 2012


Addi(Posted 2012) [#3]
Could you give us some code?


Nitsua_Revaew(Posted 2012) [#4]
i dont know what happened. I deleted the part i was having trouble with and redid it, and now it works fine. Thanks though!


Nitsua_Revaew(Posted 2012) [#5]
ok sorry, i have tried again, and now it stops working. I get an array index out of bounds error. Is it possible to have multiple arrays?


Yasha(Posted 2012) [#6]
Yes, it is.

If you get an "Array index out of bounds" error, it means what it says: you're trying to access the array with an invalid index, either negative, or too high for its current range.

We can't really say more than that without seeing the problem code.

Last edited 2012


Nitsua_Revaew(Posted 2012) [#7]
ok, i fixed it, but i have another problem. When i try to read the array, it only reads zeros. Here is my code:
global readinfo3=1
Dim prison (16,12)

Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0


While Not KeyDown(1)
Cls
startrpg()
If KeyDown(1) Then Exit
Flip
Wend

Function startrpg()
If startedrpg=True Then
For y=1 To 12
For x=1 To 16
If readinfo3=1 Then Read prison (x,y)
;right here it draws the stonefloor, which works
If prison(x,y)=0 Then
DrawImage (stonefloor,(x*50)-xoffset,(y*50)-50)
;here it should draw the prisonwall, which it doesnt, it just draws the floor
ElseIf prison(x,y)=1 Then
DrawImage (horizwall,(x*50)-xoffset,(y*50)-50)
EndIf
Next
Next
readinfo3=0
EndIf

End Function

Last edited 2012


Floyd(Posted 2012) [#8]
When i try to read the array, it only reads zeros.

That's not believable. If the array values are all zero then your program didn't read anything at all and prison(x,y) still have the default value of zero.

This is the likely culprit:
If startedrpg=True Then



Nitsua_Revaew(Posted 2012) [#9]
i need the startedrpg because this is the second level in a multipart game. I need it to only run this code after having completed the first part, when startedrpg is set to true


Andy_A(Posted 2012) [#10]
The line:
If statedrpg=True Then

needs to be outside of the function since 'startedrpg' is not a global variable. To make it a global variable would be a kludge. The best place for that test is just prior to calling the function 'startrpg()'.

While
    ;...
    If startedrpg=True Then startrpg()
    ;...
Wend


Last edited 2012