General Category => General Discussion => Topic started by: Astrosynthesist on December 27, 2017, 11:50:52 AM

Title: Large arrays
Post by: Astrosynthesist on December 27, 2017, 11:50:52 AM
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:
Code: [Select]
array1 = {{1,2,3},{4,5,6}}but then I can only index single values from that array:
Code: [Select]
print array1[1,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:
Code: [Select]
array2 = {({1,2,3}),({4,5,6})}But now I cannot subindex single values of that array without assigning each row to another variable:
Code: [Select]
myrow = array2[1]
print myrow
print myrow[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.

Title: Re: Large arrays
Post by: Vectrex32 on December 27, 2017, 12:32:33 PM
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
Title: Re: Large arrays
Post by: Astrosynthesist on December 27, 2017, 08:15:45 PM
Ah yes, the almighty underscore! Thanks.