Author Topic: Large arrays  (Read 44 times)

Astrosynthesist

  • Newbie
  • *
  • Posts: 40
    • View Profile
Large arrays
« 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]
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
{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

  • Administrator
  • Full Member
  • *****
  • Posts: 114
    • View Profile
Re: Large arrays
« Reply #1 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

Astrosynthesist

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Large arrays
« Reply #2 on: December 27, 2017, 08:15:45 PM »
Ah yes, the almighty underscore! Thanks.