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 and Loading games questions

Author
Message
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 7th Jan 2013 03:35
I am doing a little text thing and it's coming along nicely. I am not sure how to do a save/load game routine. I know do have to study up on file handling a lot more. I just want them to save the game so they can come back later load it up and continue it from where they left off.

How does it work when you make an exe file and give it to someone?

Do you create the file in DBP and pass that file along with the exe?

Just not quite sure how it works. I saw some stuff by doing a search but didn't understand it all. It can't be that difficult once you understand how to do it but that is the problem, I am missing something. There is something I am getting and once I do get it I will probably call my self stupid because I am sure it is something that is easy!

Thanks
Dragonslayer
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 7th Jan 2013 05:48 Edited at: 7th Jan 2013 05:50
They best way to look at it is to think of variables and user defined types. How you store data in these is similar to how you store data in files; just different commands.

There are many ways to load or save game files; loads of ways; loads of ways... Telling you them all will be overkill; the easiest way requires Matrix1 utilities to save INI files

Like I said above, think of writing to a file just like writing a variable. Now here is how you make your file:

Make Lookup LookupId

Now let's set a variable in the lookup; currently it resides in RAM. Let's set the current level to level 2

Set Lookup LookupId, "LevelInformation/LevelNumber", "2"

Lookup commands always use string values.

To illustrate that the procedure is similar to setting the LevelNumber value of a UDT, above we just used a frontslash instead of a dot:

LevelInformation.LevelNumber = "2"

Now, to save the lookup to file, which should not already exist; you do the following

Save Lookup To Ini LookupId, "GameFile.Dat"

Note that the extension does not need to be .INI. Open the file and observe the syntax.

To load the file back; it is easy.

Make Lookup From INI "GameFile.dat", LookupId

To retrieve a value; remembering that lookups are string queries:

Text$ = Lookup$( LookupId, "Section/Field", "DefaultText" )

Thus, to retrieve the level number:

Level = IntVal( Lookup$( LookupId, "LevelInformation/LevelNumber", "1" ) )

Then simply throw away the lookup after use, you don't need it in RAM anymore, but this will not delete the file from disk:

Delete Lookup LookupId

MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 7th Jan 2013 12:45
I agree with the use of INI files, you can also encrypt them in your own extension format so the end user cannot figure out anything and you can password lock them too, prevents cheating.

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 7th Jan 2013 23:29
I kind of get it but not really. I think I need to study the filing handling more along with this post and some stuff I found through the forum search and I should be ok.
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 8th Jan 2013 01:50
One question about save game files, character save files. When you turn your code into an exe does this code you are showing here does it modify an exe? is everything stored in the exe file or does this code create folders that you have to ship along with the exe file.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 8th Jan 2013 04:29
The example above saves the file in the current directory which is where EXE is located, usually.

You can use the Dir Exe() Matrix1 command to locate the path.

File commands do not modify your EXE. They modify other files. You can create folders from your program, or simply install the folders with your install package or archive.

So, are you stuck with the INI file commands? What are you not sure about?

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 8th Jan 2013 22:03
Well I had a little time yesterday and I have some time today. I read over the file commands a couple of times in the hands on book and I think I am gaining on it. I have learned one thing in general!

Programming, no matter which language is not easy. If I read a chapter once I may learn a little something. If I read it again tomorrow I will learn something else that I missed the first time. I have had to read some of this 3 or 4 and 5 times really good before I get it!

I am not sure on the ini commands. I am not sure what I need to save or how a game saves so the player can come back to it and pick up where he left off, or how he can have more than one saved game and also how to get the saved game back loaded up.

Here is I thought it would be, and think it should be. I thought there would have been some command that you could put in your code like save game file. Like I set up a menu option that says save game and it goes to the save game function, gives them an option to name the save then executes the save game file command.

I am sure that I am missing something very simple here and once I see it, it will be one of those ahaaa moments!

I am going to work some of those little practice programs in the book to see if I can gain anything by doing so. I think that book or any game programming book should go over the file handling commands but there should also also be a section on how to specifically have a player save and load a game. Hands on doesn't it just goes over the commands.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 8th Jan 2013 22:07
For INI files, look at Matrix1Utils on the forum, by IANM, or purchase STYX from the store...

I can only help with STYX, whereas Chris Tate can assist with the other...

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 8th Jan 2013 22:28
I will look at this. I just read this post over a couple of times and looked at that ini link. An ini file is just a text file, right? So when someone clicks on save game how does that ini file get changed to update the new locations, hitpoints, weapons etc... for this new save or is a new ini created for every new save and the old one gets deleted? and is the save/load routine the last thing you would code in your game or does it not matter.

I have a lot more to learn here. I don't know all what I would have to put into the ini file to make a good save.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 8th Jan 2013 22:37
[SAVEPOSITION01]
PlayerHP=7556
PlayerMP=658
PlayerLocation=PalaceTowerNorth
PlayerSavePoint=ThirdFloorSecondRoom
PlayerExperienceLevel=35

[SAVEPOSITION02]
PlayerHP=8235
PlayerMP=724
PlayerLocation=PalaceTowerSouth
PlayerSavePoint=EithFloorSecondRoom
PlayerExperienceLevel=39

Basically there are Sections and Attributes and Values...

Section is [This]
Attribute is before this =
Value is after this = Here this side is the value

You simply use the same Section+Attribute+Value to overwrite the same position data within the same file...

You can obviously store the same values in individual files... making things that little bit easier...

Hopefully this will be seen as a crash course...

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 8th Jan 2013 23:50
I am going to look into the Matrix1Utils plug in when I have more time, like the weekend. I thought there would be an easy way to do this with the basic DBP file handling commands. It will probably be easy with that plug in once I know how to use the commands. I just did not want to learn a new program or commands right now but I guess that is the name of the game here.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 9th Jan 2013 01:42
Quote: "I thought there would be an easy way to do this with the basic DBP file handling commands."


It is possible with file commands, but not as easy as with INI files.

The reason there is no single solution for save game commands is that the whole point is for you to define what you mean by save game; you have the control to create your own save states. Every game is unique, what works for saving a platform game state would not suffice for a strategy game or something.

I mentioned above that you should think of it as setting variables. If you know how to store the players position in a variable; then you should understand what this demonstration is doing:



So you simply save the information, then load it back; it is up to you how it all works.

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 9th Jan 2013 02:07
I am seeing it. So to save all the info like health, gold, items, level etc... you just do it the same way? I downloaded that Plug in and will check it out when I get more time.
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 13th Jan 2013 04:27
I have the matrix1 util plug in. How do I set this up? I have never added anything into DBP before. It has 3 folders, compiler, editor and plug in user. do I just drag these to those folders in the DBP folder?
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Jan 2013 05:13
Yeah, place them in corresponding folders and run DBP in admin mode just the once to scan the added features etc

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 13th Jan 2013 15:38
Ok I dragged each folder into the corresponding folder in the DBP directory. If I go to the help folder I can open it and find the help folder for this plug in but no help comes up for it in the editor when you click help. I have been using the Indiago editor but also like the default editor and that is the one I checked for help files and that is the one I ran in admin mode.

Since I don't know a lot about this plug in or the commands could someone who is up on the matrix1 utilities plug in post a little code that would let me test it to make sure I have it installed right?

Thanks
Deagonslayer
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Jan 2013 15:43 Edited at: 13th Jan 2013 15:43
TRY



EDIT

FIXED CODE BOX

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 13th Jan 2013 15:54
I ran that code and got this error.

Could not determine parameter type of WINDOWS IS 64 BIT ( ) at line 5.

I was using the default editor. I poked around in the DBP folder and found the Matrix1 utilities files and I am pretty sure they are where they are supposed to be.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Jan 2013 15:59
Are the DLLs in the Plugins-User folder?

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 13th Jan 2013 16:07
I think I see the problem, I drug the compiler folder from the plug in into the DBP/compiler folder which created another compiler folder so they are in DBP/compiler/compiler/plug in user. I will copy the dlls into the right folder and it should work.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Jan 2013 16:07
fingers pointing [crossed XD]

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 13th Jan 2013 16:15
I made the change and it worked! thanks!!!
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Jan 2013 16:22 Edited at: 13th Jan 2013 16:22
Good Show!

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 13th Jan 2013 16:25
I also switched the help files because of the same problem but when I go to help in either editor I don't see these new commands in the help files, other than that it works!
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Jan 2013 16:59
Did you forget to copy them to the HELP directory of your main editor?

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 13th Jan 2013 17:04
No didn't do that!
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Jan 2013 17:06
facepalm!

Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 13th Jan 2013 20:51
Simply select all archive content and drag the folders into your TGC folder; such plugins are archived in a simple way for easy setup.

It will simply add the required files where they need to go. A quick backup of the TGC folder is usually advisable; but with large plugins such as Matrix1 and Advanced2d they are pretty reliable.

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 27th Jan 2013 23:14
OK I have another question I have this stuff installed but have not done much the past couple of weeks. When should I program save and load commands? Should I do it first? A lot of that stuff I saw I have not coded yet such as move commands etc...
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 28th Jan 2013 05:21
There is no single right or wrong time to make save and load commands; it falls down to your game design, plans and capabilities.

Do you need to load and save games early on? If so, then it does make sense to first create your game UDT, then get a simple game working to make sure it works before you load/save it, then create load and save functions.

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 28th Jan 2013 17:21
I want to create a list of characters and have the player be able to move them in and out of a party. I can get everything else working with one premade character.I was going to call the save load function from the create character function.[b]

Login to post a reply

Server time is: 2024-11-23 13:46:15
Your offset time is: 2024-11-23 13:46:15