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 / Save - Need Help

Author
Message
Lance Lumpy
20
Years of Service
User Offline
Joined: 21st Feb 2004
Location: On My Computer
Posted: 22nd Feb 2004 16:58
How Can I Make My Game Remember Stuff, Like A Number They Typed In. Like Save Game. I would like it if someone told me!
Thanks
Lance

Support Everton FC - They're The Best!
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 22nd Feb 2004 17:47
you can either put all the information into some arrays and then save them, or you can open a file and then write the data to the file, then you close the file and when you want to load the game again you open the file and read all the numbers/strings back into the game, for example

open to write 1,"save.dat"
write string 1,playername$
write long 1,xposition
write long 1,yposition
write long 1,score
write long 1,lives
close file 1

will amke a file called save.dat that holds the players name, his x and y co-ordinates, the score he reached and the number of lives he had left, this assumes this is all you need to reset the game, else you would also need the enemy positions and their states etc, and anything else that is needed to make the game restart at exactly the same state it was at when the player saved it, then in the main loop you check for a keypress (like "L" for example) and jump to a subroutine that allows the player the option of loading the saved game...eg:

open to read 1,"save.dat"
read string 1,playername$
read long 1,xposition
read long 1,yposition
read long 1,score
read long 1,lives
close file 1

this will read the information you saved back into the game, thus allowing you to continue from the same point you reached when you saved it, it is also a good idea to check for the save file existing and deleting any old ones before you save the new ones, look at the file handling commands and you should find what you need easily enough, remember you must close a file when you have finished writing to it or reading it, or you may lose data or corrupt the save file, and you can only ever have one name per file, use the str$ command to make numbers into strings to allow you to save and load numbered files

eg

save1.dat
save2.dat
etc

load em with

for i=1 to 5
open to read 1,"save"+str$(i)+".dat"
read string 1,player$(i)
read long 1,highscore(i)
close 1
next i

will load the names and scores for the top five players in a game, hope thats some help, cheers.

Mentor.

1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, ATI radeon 9800 pro gfx, 6 way surround sound, 2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
Lance Lumpy
20
Years of Service
User Offline
Joined: 21st Feb 2004
Location: On My Computer
Posted: 22nd Feb 2004 20:05
Thanx M8

Support Everton FC - They're The Best!

Login to post a reply

Server time is: 2024-11-26 05:24:21
Your offset time is: 2024-11-26 05:24:21