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 / Save Function

Author
Message
Omnimerc
19
Years of Service
User Offline
Joined: 24th Apr 2007
Location:
Posted: 25th Apr 2007 02:38
I currently have a game that I am working on...

I have created a HighScores function...

and it saves each time someone plays it...

And I was wondering...

Is there anyway I can create a save function where if someone needs to stop playing and quit they can do a save?

If so can someone show me a snippet?
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 25th Apr 2007 03:18
Well, depending on how the game is made, what variables are stored as what, etc. will determine how to make the save function.

Let's say you just wanted to save the score. Maybe you have a variable called score. An easy way is to make sure that score is a string variable. If it's not, you can make it one with the STR$() function.

Ok score (an interger) equals 5000. Now let's turn it into a string and save it.

savescore$ = str$(score)

I just created a string variable called savescore$ out of the integer score. Now to save it:



to read it back:



The thing about saving and loading a file is, if it exists, it can't be created, if doesn't exist, it can't be loaded. So somewhere in your function you have to test if the file exist and then handle that condition. Here's a function that combines both the reading and writing of the score. You will have to modify the path to a location you want. I have a delete file call in the function so you'll want to make sure that a file named highscore.txt that you want to keep isn't in the path you choose.



You can apply this idea to whatever variables in the game that you want to save so that the next time someone wants to play, they can load up the saved values.

Enjoy your day.
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th Apr 2007 03:56
Reading the OP, I think he's talking more about how to save the current score of an aborted game when you exit it, rather than when the game ends naturally - as opposed to the technicalities of actually saving the game score itself.

If I'm understanding this correctly then the score is known at the point you decide to quit.

If you put the code for the hiscore's 'enter your name' bit in a subroutine or function, you call it when your game ends.

You can also call it in the same way when you exit the game - just give them the option to save just before you end the game.

TDK_Man

Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 25th Apr 2007 05:09 Edited at: 25th Apr 2007 05:45
Oh, I see.

Enjoy your day.
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th Apr 2007 05:19

Login to post a reply

Server time is: 2026-07-06 06:43:53
Your offset time is: 2026-07-06 06:43:53