Array fields with non-constant entry counts

BlitzPlus Forums/BlitzPlus Programming/Array fields with non-constant entry counts

schilcote(Posted 2011) [#1]
I need to store an array in a type object. I know I can do this with "Field array[10]", but the number of entries I need isn't constant over multiple sessions (that is, it won't change while the program is running, but it might have a different value next time the program is run) and that syntax only accepts constants.

I suppose I could make a two-dimensional array with Dim(), but that seems inelegant and it seems rather odd that one method of creating arrays allows variable sizes and the other doesn't. Am I missing something?


Matty(Posted 2011) [#2]
Do you have to use an array, you could use a bank which is much more flexible than an array in any case....


schilcote(Posted 2011) [#3]
It's also more complicated...

See, I'm making an Elite-style space trading game, and I need to keep track of how much of each type of good each planet has (supply vs. demand, you know). The game is built so that the player can modify the data files and add new stuff to it.

I guess it isn't really that important that players be able to add new otherwise-generic items to the game. I just wanted to see if I could do it...


epiblitikos(Posted 2011) [#4]
The only solution that comes to mind for BlitzPlus that isn't banks is to set an arbitrarily high size and govern the 'real' size independently of it. That obviously uses extra memory to store and CPU to manage, though.


Matty(Posted 2011) [#5]
As said, a bank would handle this fine.


TAS(Posted 2011) [#6]
A string field should work and be easy to implement. If the values are 0-255 you can use Chr() and Asc() to store and read them. Or you can store them as text after you make sure that the text is always the same size.


Timjo(Posted 2011) [#7]
It is possible to use types within types - but it's quite hard to get your head around at first. (for me, anyway)

Not sure if it will be of any use, but it's here...

http://www.blitzbasic.com/codearcs/codearcs.php?code=8