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 / Want to learn how to save and load data? then look here

Author
Message
Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 26th May 2005 08:00 Edited at: 26th Jun 2005 07:21
Lately I've being seeing a bunch of posts about people asking how to save and load game data, so I've decided to help. On my site I have created tutorials that explain in detail how to save and load game data using DarkBasic's file commands, or array commands. You can find the tutorials here:

http://www.freewebs.com/underworld1020/tutorials.htm

I've also created my own file function set that will also save and load game data. I feel they are easier to use and also have the advantage of saving or loading data from a specic line in a file, and also the files are more organized because each line is marked with its line number.

Now you should probably read the tutorials I created for DarkBasic's commands, BEFORE trying to use mine, but thats your choice.

Here's how to use my functions:

The first thing you must do is copy and paste all of this:

Into the END of your program code. Then you are ready to use the functions.

Create_File():

To use the Create_File() function simply type in Create_File(. Like This:

Then the name of the file you want to create, make sure to include its extension and also put it in quotes. Like This:

Then type in a comma and then type in how many lines you want the file to be and then then end the parenthsis. Like This:

What that will do is create a file on your computer named MyData.txt and will make it 5 lines in length. You can name the file anything you want and make it as long as you want.

Here's what it would look like if you opened up the file that we created:

It shows how many lines are in the file all together on the first line and then it numbers all the remaining lines with the correct line number according to your data. Thats it for the Create_File function.

Write_String():

The first thing you do to use the Write_String() command is type in Write_String(. Like This:

Then you must type in what file you want to store the data in. Make sure you include its extension and put it in quotes. Like This:

Also make sure that you've already created that file with the Create_File function before using it here. Then you type in a comma and then the line number you want to store the data to and then type in a comma. Like This:

Then the you must tell it what you want to store on that line. Simply type anything you want to store, but make sure you put it in quotes. Then type in a parathesis Like This:


That will store the string on line 3 of the file called MyData.txt, you can store numbers or words anything you want, just make sure its in quotes.

Read_String():

The Read_String() function loads the data into your program. Now the Read_String() function returns data, so the first thing to do is type in what string you want to store the data into. Like This:

If you don't want it to be a string, but a number instead type it in like this:

Then type in Read_String(. Like This:

Then type in what file you want to read from make sure you've already used the Create_File() for the file and also have used the Write_String() function to store data to the file. Also be sure to include the files extension and also put it in quotes. Like This:

Then type in a comma, and then type in what line number you want to load the data from then type in a parathesis Like This:

Now thats all there is to it, but if you did the Val( thing then your code should end with a parathesis. Like This:


Here's An example of the functions in use, just run the code and you'll see:


Now if you still don't understand and you HAVE already read the tutorials also, then just ask me and I'll help you out

Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 26th May 2005 08:27 Edited at: 26th May 2005 08:38
Ok, I'm done editing my post, look above. Enjoy!

EDIT: By the way I'm working on a full Pong tutorial right now, it should be done in a couple of days.

DARKGuy
21
Years of Service
User Offline
Joined: 28th Nov 2003
Location:
Posted: 27th May 2005 00:01
Hey dude, this is AWESOME! these are awesome tutorials and code, will you allow me to link them from my site? I'm making a new layout and stuff so this looks quite good help

Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 27th May 2005 04:10
Sure you can do what ever you like with them, I'll be putting the functions I created on my site soon. And by the way I've got about 40% of the Pong tutorial done last night. I made it so their just a basic Pong game and then a section that shows you step by step how to add different kinds of advanced features to the game, I think people will really like it when I'm done.

KYP
20
Years of Service
User Offline
Joined: 5th May 2005
Location: 01110000
Posted: 27th May 2005 11:16 Edited at: 28th May 2005 08:22
awesome.


edit: oops. i should have used an array to save data.... heh heh....

program 'till your butt falls off, and never give up.
comm_jak
20
Years of Service
User Offline
Joined: 31st May 2004
Location: FOB: Fields Of Battle
Posted: 28th May 2005 15:05
wow! incredible much better than the way i was doing it!!!

I will command the troops to victory
Big Man
20
Years of Service
User Offline
Joined: 4th Feb 2005
Location: BEHIND YOU!!!! (but I live in England)
Posted: 26th Jun 2005 06:08
Hi Underworld

I dont know whether or not you remember me (Big man) but you were giving me tutorials a couple of months ago.
I was wondering can you help with a problem.
I am writing a 3d first person shooter and have got as far as adding gun shooting sounds, but the only way I know to do it is inside the main loop which is producing the wrong effect for an Ak-47.

Our aim is to keep the loo's clean, your aim can help.
Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 26th Jun 2005 08:01 Edited at: 26th Jun 2005 08:03
@Bigman - Email me at [email protected], or my AIM username is Underworld1020, I'm not sure what part exactly you need help with.

Also guys I made a mistake when I wrote the little tutorial for the functions I created. It had to do with the Str$() command I meant to use the Val() command. I edited the post its fixed now...

Big Man
20
Years of Service
User Offline
Joined: 4th Feb 2005
Location: BEHIND YOU!!!! (but I live in England)
Posted: 27th Jun 2005 02:01
Can't we just use the forum.

This is my problem:
I have the main loop and in it I have it so when you click the mouse button 1 it plays the gun sound but this just seems to repeat the first nano second of the sound and it sounds really stupid.
please help

Our aim is to keep the loo's clean, your aim can help.
Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 27th Jun 2005 11:59 Edited at: 27th Jun 2005 12:01
So, something like this:


Line 1: loads the gun sound in as sound #1
Line 2: starts the main loop
Line 3: says if the left mouse button is being pressed then goto line 4, else goto line 7
Line 4: plays the gun sound 1 time
Line 5: Waits for the end of the gun sound, then continues(Repeat command and Sound Playing command)
Line 6: EndIf
Line 7: Ends the main loop, goes back to line 2

Is that what your looking for, if not then post your code, and I'll try to fix it. Hope that helps

Big Man
20
Years of Service
User Offline
Joined: 4th Feb 2005
Location: BEHIND YOU!!!! (but I live in England)
Posted: 8th Jul 2005 02:53 Edited at: 9th Jul 2005 03:09
Not Quite.
It plays the sound like I want it to but whilst the sound is playing the camera isn't moving.
Cheers for this code though it was a big leap forward in my game I had been trying for so long.

Our aim is to keep the loo's clean, your aim can help.
Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 11th Jul 2005 10:19
This should be what your looking for:


Let me know if thats right.

Colonel Cool
19
Years of Service
User Offline
Joined: 3rd Aug 2005
Location: Somewhere
Posted: 4th Aug 2005 21:30
Thanks for posting this, I really needed help saving stuff in my
Map Editor could never get it to work. Anybody who wants the map editor
just ask me, it'll be done soon.

Login to post a reply

Server time is: 2025-05-22 22:38:50
Your offset time is: 2025-05-22 22:38:50