Restoring Data with a variable

Blitz3D Forums/Blitz3D Beginners Area/Restoring Data with a variable

OkTayNe(Posted 2003) [#1]
hi all, my first problem with B3D.
Is it possible to use the Restore command with some type of variable to point to a label?
My Game has a lot of levels (100+) which are pulled from data statements and dont want to hard code them all as: Restore Level1, Restore Level2 etc.
I need a way to access these levels from a simple variable holding the current level.

Any help would be appreciated
OkTayNE


Curtastic(Posted 2003) [#2]
ah another reason for arrays of labels.
I want them for gosub.


semar(Posted 2003) [#3]
@OkTayNe,
the Restore command requires a static label, sorry.

What you can do, is to set a terminator value at the end of each level data statements; then you can point to the data related, for example, to the third level, by reading all the previous data, until you reach the beginning of the third level data.

Example.

Suppose you want to read the values for the level 3. To accomplish this task, you have to discard all the values between the level 1 and (3-1 = ) 2.
we use a terminator value of -999
One way could be:
const terminator = -999 ;this value is used to determine the end of a level data sequence

Restore LEVELS ;restore all the data

current_level = 3 ;set the wanted level

discard = current_level - 1 ;will discard the first n-1 level data values

while discard ;loop for discard data values

read value ;read data

if value = terminator then
   discard = discard - 1 ;when discard = 0, then will exit the while loop
endif

wend

;now you can read all the values related to level 3

value = 0

while value <> terminator

read value ;read values for your level

wend

;here is a sample data
.LEVELS
Data 1,2,3,4,5,6,7,8,9,0,1,2,-999 ;level 1
Data 1,2,3,4,5,6,-999 ;level 2
Data 1,2,3,4,5,6,7,8,9,11,-999 ;level 3
Data 5,6,7,8,3,2,41,2,3,4,5,6,7,8,9,11,-999 ;level 4


Hope this has sense for you,
Sergio.


OkTayNe(Posted 2003) [#4]
thanks semar, i had thought about doing something like that but i think it would cause the level build times to increase too towards the later levels, each level has quite a bit of data.
oh well it looks like i'm going to have to look at another way of building my levels or reduce the amount.
cheers again
OkTayNe


semar(Posted 2003) [#5]
If the speed is a critical issue, you can load all the levels data in a 2D array at the starting of the program; later, read the values for a level from the array itself.

Suppose you have 1000 values to be red for each level, and 100 levels.

Then you can dimension an array like
CONST terminator = -999 ;level data terminator
dim level(100,1000)
;fill the array with level data, and terminator
read_all_the_levels_data_into_the_array()

;and read the values for the level number 'L' with this:
for n = 1 to 1000
generic_value = level(L,n)
if generic_value = terminator then
exit
endif
next


Sergio.


OkTayNe(Posted 2003) [#6]
Thats cracked it semar, although i will have to change the structure of my data (which is easy).
Your help has been noted..cheers

OkTayNe