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.

DarkBASIC Discussion / Saving game details to an external file

Author
Message
Red general
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: United Kingdom
Posted: 11th Feb 2003 13:41
How do you save the variables, arrays, text, etc to an external file and then when the player decides to load game, it loads the details from that file, and he continues from where he left off
Thanks
RED GENERAL
My computer melts regulary - perhaps it likes being fondue
Tywald
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sweden
Posted: 11th Feb 2003 14:01
Redgeneral:

This small piece of code should help you.

IF FILE EXISTS(name of your file) = 1 THEN DELETE FILE("nam of your file)
OPEN TO WRITE "name of your file",1
WRITE FLOAT 1,cash# `<- If you want to save a real number.
WRITE STRING 1,name$ `<- If you want to save a string.
WRITE LONG 1,total_units `<- If you want to save a number.
CLOSE FILE 1

To load a game:
OPEN TO READ "name of your file",1
READ FLOAT 1,cash#
READ STRING 1,name$
READ LONG 1,total_units
CLOSE FILE 1

Notice that you must read the variables in the same order as you saved them eg. if you start to save the amount of cash the player has as a real number then you must also when you load the file start to load a real number.

- Tywald
Red general
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: United Kingdom
Posted: 11th Feb 2003 14:46
What do arrays get writen as? Float, string, long, or something else?
Thanks so far
RED GENERAL

My computer melts regulary - perhaps it likes being fondue
Tywald
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sweden
Posted: 11th Feb 2003 15:01
Redgeneral:

You can use the SAVE ARRAY (after you have used the OPEN TO WRITE command) command for that and when you want to load it back then use the LOAD ARRAY command, but it´s still important to remember in which order you saved them.

- Tywald
adamsmasher23
21
Years of Service
User Offline
Joined: 31st Jan 2003
Location: United States
Posted: 11th Feb 2003 15:07
I have found a way to 'label' stored variables. I will post it later.

Whatever I did it wasn't me!
adamsmasher23
21
Years of Service
User Offline
Joined: 31st Jan 2003
Location: United States
Posted: 11th Feb 2003 15:14
OK, here is the read/write code. If you need any help, email me at adamsmasher23 at hotmail dot com.



Whatever I did it wasn't me!

Login to post a reply

Server time is: 2024-05-25 04:17:12
Your offset time is: 2024-05-25 04:17:12