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.

Author
Message
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 14th Aug 2003 09:39
i am making a ttext rpg for my friend...is there a way that i can have him make a character on db and then save it? i know of the write and read but don't know anything about them..thanx in advance
"When you were born, you cried and the world rejoiced. Live so when you die, the world cries and you rejoice."
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 14th Aug 2003 15:22 Edited at: 14th Aug 2003 15:23
how do you have your character made up?, if he`s made from seperate variables like

name$="norbert"
skill$="yak hurdleing"
stamina=1
strength=2

then the easiest way to do it without rewriting your code is to do

save_player:
if file exist "savedplayer" then delete file "savedplayer"
open to write "savedplayer",1
write string 1,name$
write string 1,skill$
write long 1,stamina
write long 1,strength
close file 1
return

and to set the player back to what he was do

load_player:
if file exist "savedplayer"
open file to read "savedplayer",1
read string 1,name$
read string 1,skill$
read long 1,stamina
read long 1,strength
close file 1
else
text 200,200,"ERROR! no save file available to load!"
sync
wait 2000
endif
return

all you have to do is write the data in the correct format to the file and then read it back in the correct format and the same sequence into your variables, cheers.

Mentor.

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 14th Aug 2003 18:37
I never did this but from a programming standpoint in general, read and write saved characters to files like mentioned above and use User Defined Types in DBP to hold their data in runtime. Much neater that way - all properties of char are stored under one main variable (the Type)

good luck
Rustler

How do ya do there son
Mnemonix
21
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 17th Aug 2003 00:40
i agree with CattleRustler. In this case The UDT(user defined type) will be your best friend. Not only can it be used to store information aobut the character but also about the world, about objects, about rooms and well..er you get the picture

"We are getting aggravated"
"Yes, we are"
dark puppus
21
Years of Service
User Offline
Joined: 16th Aug 2003
Location:
Posted: 17th Aug 2003 02:54
i'heard of a user definition of types in dbp ?

i've searched for this feature, but i have'nt found it, can you tell me what's the command for this ?

Mnemonix
21
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 17th Aug 2003 03:49
indeed i can


type player

name as string
hp as integer
mp as integer

endtype


typing that lets u define variables by typing elsewhere


var as player


then u type

player.name="dave"
player.hp=23

etc.

"We are getting aggravated"
"Yes, we are"
haXor
21
Years of Service
User Offline
Joined: 12th May 2003
Location: United States
Posted: 18th Aug 2003 01:26
does it matter what type of file this info is stored in? like *.txt or *.rtf

Sup Kids
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 18th Aug 2003 02:07
I would use .txt just to keep things simple. I wouldn't use rtf as those files contain formatting data embedded in them so it may/may not cause some grief. If you want to get fancy, use ini files and use win32 dlls to call GetPrivateProfileString and WritePrivateProfileString. This way you have a key/data structure that is enforced by windows itself. If you are new to windows programming look on the net for info on the function I mentioned above. It may seem like too much at first but I swear by it in VB programming. You end up typing way less code to use windows functions rather than dealing with txt or other flat files.

let me know how you make out
Rustler

How do ya do there son

Login to post a reply

Server time is: 2024-09-20 19:39:32
Your offset time is: 2024-09-20 19:39:32