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 / saving profiles, saving score, list of profiles, how do I do it?

Author
Message
mr_fan
19
Years of Service
User Offline
Joined: 18th Mar 2005
Location: look... behind you.
Posted: 20th Nov 2005 05:59
how do do somthing like in halo, where your state of health, ammo, and progress is saved? and how you can choose diferent profiles, where the state of the player, is diferent? as well as high scores? I am using dark basic professional. any tutorials, or examples would be useful. I have no expierience in saving data or any of that though, I could never realy figure it out. I figured one of theses days I need to though.

rvb Church: "hey, look, his armor its, red."
rvb Tucker: "well that'l explain how he got past our defences."
rvb Caboose : "Actuley he came through the back."
Freddy 007
19
Years of Service
User Offline
Joined: 30th Nov 2004
Location: Denmark
Posted: 20th Nov 2005 13:28
Use you can save values to a file like this:



It really simple. I first use the OPEN TO WRITE filenumber, filename$ command to open a file to write data to. Next, when the file is opened, I use the WRITE STRING filenumber, string$ to write the value to the file(the STR$(value) converts a numeric value to string). You might think: ,, Why use WRITE STRING when it's a numeric value he's saving?". Again, really simple. It's so I can write comments to the things I'm saving in the file. But that's not important right now.
Next I close the file by using the CLOSE FILE filenumber command. Now. if you run this code, then you should be able to find a text-document on your C:\. If you open the file, it should say "10", because that's the value we stored earlier. If you want to acces the file again, and now read the value from it, you simply do like this:



First I open the spesific file by using the OPEN TO READ command, and then I read the string we saved before(READ STRING filenumber, string$). Then close the file. Now we have the value stored in the string myVar$, but we want it to be an integer number. For that, we use the VAL(string$) command to convert the value to numeric, and then we store it in the myVar-variable using the assignment operator(=). After that, I simply print the value on the screen.

Of course you can store multiple values in one file, and if you're unsure about how to do this, just ask


I can't be fired... Slaves are SOLD!
mr_fan
19
Years of Service
User Offline
Joined: 18th Mar 2005
Location: look... behind you.
Posted: 20th Nov 2005 17:49
ah, so... that first part, would be for whenever I kill a monster, and that second part would be for viewing the high scores, right? somthing like:
right? but, for the first part, wouldn't that print 10 over and over, every time I kill a monster?

rvb Church: "hey, look, his armor its, red."
rvb Tucker: "well that'l explain how he got past our defences."
rvb Caboose : "Actuley he came through the back."
Freddy 007
19
Years of Service
User Offline
Joined: 30th Nov 2004
Location: Denmark
Posted: 20th Nov 2005 17:54
Yeah, you have to use the OPEN TO WRITE and write a new value if you want it to change. But wouldn't it be easier just to store the score in a variable throughout the entire level, and then print the highscore to the player, and save it in a file?


I can't be fired... Slaves are SOLD!
mr_fan
19
Years of Service
User Offline
Joined: 18th Mar 2005
Location: look... behind you.
Posted: 20th Nov 2005 19:11 Edited at: 20th Nov 2005 19:20
what do you mean? if you could post a tutorial on how to make a high scores with the names of the profile who made the score, and in order of scorem, that would be great, somthing like
bob......1205
amy......324
shan......12
what I am trying to do is make a butten and when you click it, the high scores appear. and when you click it again, it disapears. I'm sorry if I sound like a noob, I'm just not that good with these things.

rvb Church: "hey, look, his armor its, red."
rvb Tucker: "well that'l explain how he got past our defences."
rvb Caboose : "Actuley he came through the back."
Freddy 007
19
Years of Service
User Offline
Joined: 30th Nov 2004
Location: Denmark
Posted: 20th Nov 2005 21:08
Here, I've made a simple example. This program asks the user for input, and then writes the value to a file. Next time you open the program, it will show you the variables that was saved to the file last time the program was run. Then you will be able to change the values from within the program, and see how it works. The source is commented.




I can't be fired... Slaves are SOLD!

Login to post a reply

Server time is: 2024-11-27 12:37:57
Your offset time is: 2024-11-27 12:37:57