Save Files
Blitz3D Forums/Blitz3D Beginners Area/Save Files
| ||
I got this program Two days ago, but before this I was messing around with the demo version. I know some but what I do Is limited. I would like to know how you would save game progress in blitz. |
| ||
I'm kinda noob to saving games also BUT: depending on what kind of game it is, you can save a huge amount of variables into a .bb file, each telling the computer something about the current progress in the game. The easiest way to save is a save-point system, located outside combat, etc. so you don't have to worry about saving the locations of each bullet in the air, the npc AI states, the npc locations, etc. Leaving only some player information, and which save point it is located at to be loaded. |
| ||
Save game systems really need to be implemented from the start, also -- it's not a pleasant task to retrofit a save/load game system. 'Start Game' should really be 'Load Game' but with all vars set to their initial positions. |
| ||
Chwaga, The easiest way to save is a save-point system How would you do that? |
| ||
OK, think like this: every so often in a game, there is a floating "SAVE GAME" object, that if you walk up to it, and click on it, it saves the game. If these SAVE GAME objects were located it secluded, isolated areas without NPC's etc. to track, you could load it by putting the player in the general area of that SAVE GAME "checkpoint", and load the general player attributes (health, inventory, etc.). |
| ||
No I meant, do you have a code example, I am sorry, I am really new. If it is to difficult to waste your time on then don't, but it would be nice. |
| ||
Well, for example, you will no doubt have variables to hold your players health, position (x,y,z), items carried. Basically when you save, you create a small file on the hard disc, or if it's just a quick save, just use other variables. File on Hard Disc: ; Open a file to write to fileout = WriteFile("mysave.dat") ; Write the information to the file WriteInt ( fileout, Health ) WriteInt ( fileout, Score ) WriteInt ( fileout, Level ) WriteInt ( fileout, x) WriteInt ( fileout, y) WriteInt ( fileout, z) ; Close the file CloseFile( fileout ) You have created a file, in the same folder as the code is saved to. This contains the information you wrote out. I lifted the Writefile stuff straight from the manual. You will however will need to structure your game code properly. If it's a pacman game, you'd only need to save the level and players score. Then simply load the level variable and score variable in, overwriting the games current variables for them. If it's an adventure game, you will have a whole host of other information to save, like which game events have been triggered, characters that are dead, story progression... etc Alot more complicated. Btw, to load the save file back in... ; Open the file to Read filein = ReadFile("mysave.dat") ; Lets read the Greatest score from the file Health = ReadInt( filein) Score = ReadInt( filein) Level = ReadInt( filein ) x = ReadInt( filein ) y = ReadInt( filein ) z = ReadInt( filein ) ; Close the file once reading is finished CloseFile( filein ) **** Make sure you read exactly what you've written. I mean, if you wrote Int to the file, read back Int's, don't try and read back Bytes, or your info will get jumbled, and error's will crop up. |
| ||
So If I wanted to save the xyz coords of a mesh, or something, would I do:fileout = WriteFile("mysave.dat") cow=LoadMesh("Cow.3ds") xyz=Entityx(cow) + Entityy(cow) + Entityz(cow) ; Write the information to the file WriteInt ( fileout, xyz ) CloseFile( fileout ) I am still learning so please bear with me. |
| ||
In my example above, xyz is not an integer, what command would I use for that? |
| ||
Hi Blitz3dCoder - the code you've posted above will not do anything. 'xyz' will simply be the sum of the 3 coordinate values and is useless information. You are better off doing something like this:cow=loadmesh("cow.3ds") fileout=writefile("mysave.dat") writefloat fileout,entityx(cow) writefloat fileout,entityy(cow) writefloat fileout,entityz(cow) closefile fileout or if you want the file to be easily readable by a human then you could replace writefloat with writeline, you may lose some accuracy but it can easily be edited in a text editor like notepad then. |
| ||
Thanks. If i am being a pain by asking 2 many q's tell me. |
| ||
nah, check this one out by me... clicky |
| ||
Thnx guys! |
| ||
It's ok. Your new to it, so ask as many questions as you want :o) There's no doubt someone else will learn something by reading this thread. |
| ||
Kinda off topic here, but after a brief moment of stupidity, My website is in motion. If anybody cares, Here it is: Click here |
| ||
Looks nice and straightforward. Always like the free tools section :D |