Large arrays

Started by Astrosynthesist, December 27, 2017, 11:50:52 AM

Previous topic - Next topic

Astrosynthesist

I'm having a few issues, which I hope can be easily addressed, and both of which have to do with arrays.
First; Suppose I have a very large array in order to define a complex sprite. Is there some way to hardcode the vector list into the array in spite of the 200 character limit? I cannot find a convenient way to create a sprite over multiple lines unless I just create multiple sprites and overlap them or initialize an empty array and populate it over multiple lines, which I could do but would prefer not to.
Secondly, I cannot find a way to extract rows from multidimensional arrays;
I can define an array like this:
array1 = {{1,2,3},{4,5,6}}
but then I can only index single values from that array:
print array1[1,2]
2
print array1[1]
print array1[1]
      ^ Wrong number of indices inside []

Now I cannot reference rows in that array, I would have to iterate over them in a for loop.
Alternatively I could define the array like this:
array2 = {({1,2,3}),({4,5,6})}
But now I cannot subindex single values of that array without assigning each row to another variable:
myrow = array2[1]
print myrow
{1,2,3}
print myrow[2]
2
print array2[1,2]
      ^ Wrong number of indices inside []
print array2[1][2]
               ^ Expected end of line

So as far as I understand it I cannot have my cake and eat it too, I can either have my cake or eat it. :)
I'm just wondering if I'm missing something in the syntax or if this is how it needs to be worked with.

Thanks!

Vectrex32

Hi Astro,

Take a look at the included game, lunar.bas. At line 60, terrainTemplate is initialized as a very large array. Does this do what you want?

Sadly, there is no built-in way to reference the row of an array. This is BASIC, not C. :-( It's not as elegant or efficient, but you could write a function that returns a copy of a row of an array. Use the UBound function to find the width of the input array and pass it as the dimension of the output array in the DIM statement.

As for cake: it has no purpose other than to be eaten, so why would you want to have it?

- Bob

Astrosynthesist

Ah yes, the almighty underscore! Thanks.