The way I handle saves in my text rpg is when you start the game it asks for a name, this is the profile name, the game automatically makes a folder in your documents with the name of the game, in there, it makes a folder called "Profiles" and in there, it makes a folder with the name you entered when you started the game, then it creates text files in there for each character, I format it like so:
name$(Name of the character)
lvl(Level of the character)
xp(Experience gained by the character)
gold(Gold owned by the character)
hp(Current HP of the character)
mp(Current MP of the character)
prog(Progression, this is incremented by one after an important event, and each important event will only display if this is below a certain number, it's a bit too linear but it works)
race$(Race name)
race(Race integer 1-4)
atk(Stat)
def(Stat)
mag(Stat)
I then use this to load and save:
Save:
createchar:
gosub title rem This just prints the title at the top
print "Welcome to character creation!"
print "First, name your character."
input ": ",charname$ rem This is your characters name
open to write 1,char$
write string 1,charname$
remstart This writes your characters name onto the first line of the file, if you use write string multiple times on the same file, it will read the next line down each time
remend
write string 1,"1" rem Writes level
write string 1,"0" rem Writes XP
write string 1,"0" rem Writes Gold
write string 1,"10" rem Writes HP
write string 1,"10" rem Writes MP
write string 1,"0" rem Writes Prog
gosub title remstart the first line of the title sub is cls, so whenever you reprint the title it clears the screen
remend
print "Now select your race"
print "1) Human (No stat changes)"
print "2) Elf (+1 Magic, -1 Defence)"
print "3) Dwarf (+1 Attack, -1 Magic)"
print "4) Stoneman (+1 Defence, -1 Attack)"
input ": ",I$
if I$ = "1"
race$ = "Human"
race = 1
write string 1,race$ rem Writes the race string
write string 1,"1" rem Writes the race int
rem These lines below write the 3 stats
write string 1,"2"
atk = 2
write string 1,"2"
atk = 2
write string 1,"2"
atk = 2
endif
if I$ = "2"
race$ = "Elf"
race = 2
write string 1,race$
write string 1,"2"
write string 1,"2"
atk = 2
write string 1,"1"
def = 1
write string 1,"3"
mag = 3
endif
if I$ = "3"
race$ = "Dwarf"
race = 3
write string 1,race$
write string 1,"3"
write string 1,"3"
atk = 3
write string 1,"2"
def = 2
write string 1,"1"
mag = 1
endif
if I$ = "4"
race$ = "Stoneman"
race = 4
write string 1,race$
write string 1,"4"
write string 1,"1"
atk = 1
write string 1,"3"
def = 3
write string 1,"2"
mag = 2
endif
if race < 1
gosub invalidinput
else
close file 1
remstart Closes the file, as the file has not been closed until now, every time we excecuted write string, it wrote it onto a new line
remend
goto start
endif
The final save looks like this:
Darius
1
0
0
10
10
0
Dwarf
3
3
2
1
My loading code includes a debug option, if this is set to true then the program will print the contents of the save file before continuing:
loadchar:
open to read 1,char$ rem Opens the file
read string 1,charname$ rem Reads the name
read string 1,I$ rem Reads the level, like with the write string command, the read string command will read the next new line every time until the file is closed
lvl = val(I$) rem Assigns the level a variable, this is only needed when the output required is an integer, as reading from a file using read string always returns a string, and this second line is needed (See Below)
rem The val(string$) command is used to turn a string into an integer, this works fine when the string is a number anyway, I am not sure of the output when the string is words, I assume it converts it using some method.
read string 1,I$ rem Reads the xp
xp = val(I$) rem assigns the xp a variable
read string 1,I$ rem you get the idea
gold = val(I$)
read string 1,I$
hp = val(I$)
read string 1,I$
mp = val(I$)
read string 1,I$
prog = val(I$)
read string 1,race$
read string 1,I$
race = val(I$)
read string 1,I$
atk = val(I$)
read string 1,I$
def = val(I$)
read string 1,I$
mag = val(I$)
if debug = 1 rem this is the debug function
gosub title
print "Name: ",charname$
print "Level: ",lvl
print "Exp: ",xp
print "Gold: ",gold
print "Health: ",hp
print "Mana: ",mp
print "Prog: ",prog
print "Race: ",race$
print "RaceInt: ",race
print "Atk: ",atk
print "Def: ",def
print "Mag: ",mag
wait key rem Waits for a key to be pressed before clearing the debug info and continuing with the code
cls
endif
goto start
I hope this is fairly easy to understand, I'm relatively new to DBPro so my code may be poor or inefficient, but it works fine for me, no noticeable waiting time, this may not be the case for large save files however