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 Professional Discussion / Save game tutorial

Author
Message
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 7th Nov 2010 22:16
I have noticed a lot of requests about how to save your data and retrieve it. So I thought I would post a little example to try to show how easy it can be. The following code is a very basic program that lets you move a square around the screen. Press Enter and you will save your position. Exit the game reload it and hey presto you are in the same position you left it at!


You can do this using other methods, such as open to write. But if you are struggling to get your head round opening and closing files and reading them in, arrays are far easier, and slightly quicker to setup and use. All I do in this program is to first create my image and data components, then check if the map.dat file exists. If it doesn't it uses default settings and runs the game. If it does it loads the array, puts the arrays values into the x and y variables, and runs the game. Deleting the array file (map.dat) manually or with a little more code will cause automatic reset, so can be used for reset purposes within the game also.
Obviously you can expand on that array or add more of them, just remember to load all your array data back into the required variables and vice versa in game. Or just use the array directly instead of using temp variables, which I prefer not to do on the whole.
I hope this helps anyone struggling with saving their games. Any questions or comments, I will try to help if anyone does not understand my attempt to explain the basics.

http://s6.bitefight.org/c.php?uid=103081
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Nov 2010 10:28
Well done Vader, I'm sure glad Luke saved you when he did...

I haven't used saving arrays for this before and actually it's quite a logical way to do it.

Some of IanM's commands might be another simple way to save lots of data (Memory Banks)...

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 9th Nov 2010 13:42
Thanks. I have used this method for saving game data since I first started using DB Classic before it was called classic lol. I tend to use open to read and write to alter existing files like csv etc. For my own data I stick to arrays. There are a lot od useful commands in Iam M's utils but this is just to show standard commands in action. I avoid using any add on unless I feel I need it.
I should probably have called this an example rather than tutorial, but from the looks of the number of hits and reply's, I assume everyone can see how it works easy enough. I hope your games making goes well anyway, baxslash, I am struggling for inspiration at the moment lol.

http://s6.bitefight.org/c.php?uid=103081
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th Nov 2010 13:52
Quote: "I hope your games making goes well anyway, baxslash, I am struggling for inspiration at the moment lol."

It's going pretty well thanks DVader, inspiration is something I have too much of when it comes to game making... I need to reel myself in. If you fancy a joint project some time (I've always got several on the go), just in case you are looking for something to do that is... maybe it would help get the juices flowing again?

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Nov 2010 14:13
Quote: "Some of IanM's commands might be another simple way to save lots of data (Memory Banks)..."

If you use the datafiles plug-in from my pack, you can also save UDT arrays and all DBPro standard types (double float, double integer etc).

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 9th Nov 2010 15:35
Ian M - UDT's are a pain in DB not saving so that would be useful. I have got round that in the past by converting the udt array into a standard one, then saving and reloading it, and then putting it back into the udt array in the project. bit of a faff mind, but I hardly ever use them. So your plugin would be useful if I was doing something that required a very large database and wanted to use udt arrays for keeping my sanity. I will keep it in mind for future projects.
baxslash - not sure my coding would be good enough to help you on your projects, but if I thought I could help I would. Don't know about you but I always struggle to find/make enough graphics of one type to do anything semi big. The gamestore for instance has some areas reasonably covered, but others are woefully lacking. It sort of limits ideas. That's probably why theres so many zombie games out there. Although I do like a good Zombie game lol.

http://s6.bitefight.org/c.php?uid=103081
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th Nov 2010 15:49
Quote: "not sure my coding would be good enough to help you on your projects, but if I thought I could help I would."

You've been coding much longer than me my friend, I'm sure you could teach me a lot more than I could teach you!

Quote: "Don't know about you but I always struggle to find/make enough graphics of one type to do anything semi big. The gamestore for instance has some areas reasonably covered, but others are woefully lacking. It sort of limits ideas. That's probably why theres so many zombie games out there. Although I do like a good Zombie game lol."

Yeah, getting enough assets together for any project is hard. I never struggle with 2D but 3D can take some time! As you can tell I like zombie games too... my follow up to "The Last Stand" will be even more of a testament to that!!

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 11th Nov 2010 16:26
Sorry I didn't reply earlier not really checked back since the last post. I struggle with ALL media I can draw sprites but animating is somewhat of a problem, never liked it even with Deluxe Paint 4 on the amiga, and that was way better suited to it than Paintshop Pro or Gimp or even dare I say it Photoshop.. I prefer trying to model in 3D, but hate texture mapping. I end up having to make my objects as basic as possible to make it easier to unwrap.

I'm actually toying with the idea of a space trading game like elite at the moment. Currently I'm in the process of making something that looks fairly authentic to our galaxy, then working off that, I will try to make semi random ones for the rest. Still a long way to go as I literally programmed what I have yesterday, which is pretty basic so far. I tried a game similar many years ago with a friend, but found that db (classic) had an unfortunate bug where it cut off spheres on the edges of the screen badly. Decent collision was hard too. It drove us nuts and we canned it. DB Pro has no such problems and looks very nice ( so far). Still got a bit of looking up to find more info on moons and such. At the min our moon is the only one present. Worse case scenario is it would make a nice screen saver if I gave up on the game lol. I ended up just watching the earth and moon rotating around each other a lot while compiling and testing instead of coding.
Unsure about my images as I got em off google but look ok for now. Will obviously make sure I can use them, or find ones I can use if I get to that point. I've popped a pic of it up.

http://s6.bitefight.org/c.php?uid=103081

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Nov 2010 16:37
Quote: "I'm actually toying with the idea of a space trading game like elite at the moment."

Image looks great (although the spheres need more rows & columns), I was a massive elite fan...

I have an AI system I might be using soon on another game for large scale battles. I posted a demo here:
http://forum.thegamecreators.com/?m=forum_view&t=176688&b=8

You can have the code for the AI system if you like (although it's rough and un-finished).

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 11th Nov 2010 17:19
I will have a look at it shortly. From a quick glance it looks as if your using ezrotate which I don't use. I must admit I tend to prefer to write my code from scratch rather than adapting other peoples, but sometimes you can look at other peoples code and see a solution for your problem, so I will certainly take a look at how you have done it. To start with I am only worrying about generating the universe to fly around and how best to do it. At the moment I have merely positioned all the objects in approximations of the actual positions in space, although probably too close to be properly realistic. Once I am happy with it I will convert the data into an array and then use that to make the other galaxies. That's the plan anyway off the top of my head with absolutely no real planning at all, lol
I will have to try making some ships so if you need any for your game I will be happy to send you some when I have cobbled some together. If only there was a nice inexpensive (or free) program that allowed you to paint your models in 3d. Only ones I've seen are expensive and from what I've seen of photoshop doing this, is pretty poor.
Oh I did have more segments at one point, 128 at one point lol. Currently it is 16 as it actually slowed down when I got all the planets in, even with 32. So I knocked it down to the min I could live with. It may be texture size causing it more so than segments maybe, but it has run perfect since lowering down. Possibly a LOD system of some sort would be useful, but never really done it before so would have to think a bit more how to do it.
I probably would make a detail setting in the main menu to up the detail if your machine can handle the extra load. There will be a fair bit more going on than in my simple demo so far.
The graphics look pretty good on the screenshots on your link. Did you do them or are they ones you grabbed for testing?

http://s6.bitefight.org/c.php?uid=103081
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Nov 2010 17:39 Edited at: 11th Nov 2010 17:40
Quote: "From a quick glance it looks as if your using ezrotate which I don't use."

Yes I am I think, I forgot...

Quote: "I will have to try making some ships so if you need any for your game I will be happy to send you some when I have cobbled some together."

That would be great, thanks!

Quote: "If only there was a nice inexpensive (or free) program that allowed you to paint your models in 3d."

Something like this you mean?

http://www.blacksmith3d.com/

...or this?

http://forum.thegamecreators.com/?m=forum_view&t=177555&b=8

Quote: "Possibly a LOD system of some sort would be useful"

That would be my suggestion. You could just use different spheres which you show/hide depending how close you are to the planet.

Quote: "The graphics look pretty good on the screenshots on your link. Did you do them or are they ones you grabbed for testing?"

Just some free models I found, but I may actually keep some of them.

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 11th Nov 2010 18:50
Blacksmith looks nice but a little expensive for my current pockets. the DB one from RUSSIA looks good so far, very impressive. need to look at it a bit more though as I didn't notice a way to change the actual 3d object to paint. I was going to just replace my object with his but found 50 of em in the directory! lol. So without a bit of trial and error or source code not sure what is what.

I'll let you know about any ships I make, will be doing something within the next week I imagine. Once I finish off the little bit of making all the planets orbit the sun rather than sit there as they currently do. Shouldn't take long, certainly not as long as making ships .

http://s6.bitefight.org/c.php?uid=103081

Login to post a reply

Server time is: 2024-04-19 12:46:20
Your offset time is: 2024-04-19 12:46:20