LoginLogin

How do I save and load data?

Root / Programming Questions / [.]

HedrixCreated:
I have a map that randomly generates trees via numerical array, but I need to know how to keep the map from regenerating trees if e.g. you go to a town and come back to the map... I think saving and loading the array can do the trick, but I don't know how to do so. Please help.

It looks like this...
dim map[8,8] 'real map is bigger, this is just an example
For y=0 to 7
 For x=0 to 7
  Read c
  map[x,y]=c
  If c==3 and rnd(9)==0 then c=1 elseif c==3 and rnd(90)==0 then c=2 elseif c==3 then c=0
  if c==0 then 'make the grass stuff's
  if c==1 then 'make the trees''this code isn't necessary for me to state, so I'm not including it in my example'
  if c==2 then 'make water'
  next
next

Data 1,1,1,1,1,1,1,1
Data 1,3,3,3,2,2,3,1
Data 1,3,3,2,2,3,1,1
Data 1,3,3,2,2,3,3,1
Data 1,3,3,3,3,3,3,1
Data 1,3,0,0,0,2,3,1
Data 1,1,3,3,3,3,3,1
Data 1,1,1,1,1,1,1,1

You can save an array with: SAVE "DAT:filename",ARRAY And load arrays using: LOAD "DAT:filename",ARRAY,0 (the 0 disables the dialog box that normally appears when loading files (but this can't be done while saving))

I tried that. What line of code should I have to load command?

I'm not sure what that is? If you want to make a "load save" option in a game it's as simple as doing menu stuff and calling LOAD based on the menu option.