Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Loading Arrays!!!

Author
Message
Whisper Wind
21
Years of Service
User Offline
Joined: 5th Apr 2003
Location:
Posted: 27th Apr 2003 23:32
I have tried to create a "save game" system for my mini rpg. If you save and load both in game it works perfectly. However, if you save, exit, start it up again and load it messes up. It is no regular DarkBasic error, not something like "object doesn't exist at line x". The game just crashes. Here is how my primitive save system works:
Saving: gosub convert_vars:save array "Data1", svar(15)
Loading: load array "Data1", svar(15):gosub use_vars

What it is gosubbing is in my source code. What the system is basically doing is setting the array values to important valuse in the game, such as how many potions you have, where your position is etc... Then it saves the array. Next, it loads the array, and then sets important values in the game to those in the array. Please help! Thanks.
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 27th Apr 2003 23:45
Uhm, if you're using DB Classic, just save and load the arrays as svar(0) no matter what their index numbers are, DB just ignores them anyway. Also, check to make sure before you load the array you have it initialised.

i.e
dim svar(999)
load array "data1",svar(0)

Whatever I did I didn't do it!
Whisper Wind
21
Years of Service
User Offline
Joined: 5th Apr 2003
Location:
Posted: 28th Apr 2003 00:10
Thanks for your response! Ok, I initialised it like you said and now I have figured out what is wrong, but I can't seem to fix it. The reason why it worked only in game before was because it isn't actually using the loaded arrays, only the in game ones. That is why when I tried loading after I had exited all the values came out zero. I am using DBPro, what am I missing? Please help! Thanks.
Whisper Wind
21
Years of Service
User Offline
Joined: 5th Apr 2003
Location:
Posted: 28th Apr 2003 08:28
This is driving me crazy!! I've tried a lot of things, but I can't get this to work . It seems that the array is loading, but the values for the loaded array aren't being put into the game. Loading the array is having no effect at all! The rest of my game is coming on perfectly, but its just this one thing I can't seem to get! Please help! Thanks.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Apr 2003 08:31
Can you show us the actual lines of code you are using to do the dim/loading/saving of your array?
Whisper Wind
21
Years of Service
User Offline
Joined: 5th Apr 2003
Location:
Posted: 28th Apr 2003 08:45 Edited at: 28th Apr 2003 08:56
Sure:

Saving Line: gosub convert_vars:save array "Data1", svar(15)
Loading Line: load array "Data1", svar(15):gosub use_vars

Here are the gosubs:


At the beginning of my game I just use dim svar(15) to intialise it.
I described how this system of saving was supposed to work in the first post.
Thanks for the response!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Apr 2003 08:56
Well, as kentaree said earlier, when you save/load an array you *must* specify zero within the brackets.

save array "Data", svar(0)
load array "Data", svar(0)

Also, because you are attempting to store floats within your array, you should change your array to floats also.
Whisper Wind
21
Years of Service
User Offline
Joined: 5th Apr 2003
Location:
Posted: 28th Apr 2003 09:05
Awsome! Thanks for your help guys! It works great now.

Login to post a reply

Server time is: 2024-11-24 12:44:22
Your offset time is: 2024-11-24 12:44:22