Jump to content

save and load game


Soamp
 Share

Recommended Posts

What do you mean exaclty?

I think you mean save player position, and status.

 

In this case you should create a file where you simply store all the data you may need.

I did 2 type of save in my game normally, 1 where i store the option (graphics, sound etc.) and second type is game type save.

How do this depend in your game.

As for example in a race game if you save during the race, you'll need to save all the car position, rotation, speed, eventually damage, fuel, weather, consumed tyre etc..

In an rpg you probably should save quest (best use boolean).

 

Etc.

 

If you could tell me wich game you are creating i could try to help you more in deep.

Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10.

Link to comment
Share on other sites

Hi,

In most fps games like Modern Warfare, there are some checkpoints. when you get passed them the game will be saved at that point. if you die in the game, it will be started from the last checkpoint.

I want that kind of saving.

 

thanks.

Link to comment
Share on other sites

This is easy enough, that "checkpoint" are area system normally porgrammer use radius starting from a point, or squared area or in some cases face of a navmesh to check if the player reach the point.

Normally they did this in a "clean area" (no enemy, many npc are freeze no strange fx etc..) so the save system is clean and fast.

You should check if the prior checkpoint is better, (as for example you pass a checkpoint and come back to an old one, you don't want save it) so save the position of char, his rotation and others (life, npc etc.).

You can choose if save on a file (slower) or "keep it in mind" saving it in an array or list/vector (more memory).

 

Let me know if you need more infos.

Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10.

Link to comment
Share on other sites

Other option for loading data to lua from text file, is command dofile, where loaded file has format like this:

 

file "game.data":


return
{
   pos = {0,1,2},
   name = "player1",
   other =
	{
		items =
			{"item1","item1","item1"}
	}

}


 

 

then in your script call:

 

GameData = dofile("game.data")

 

 

Chceck data:

 


print(GameData.pos[1],GameData.pos[2],GameData.pos[3])
print(GameData.name)
print(GameData.other.items[1])
print(GameData.other.items[2])
print(GameData.other.items[3])

 

Benefit is, that you don't need write parser for data.

 

EDIT:

 

When you need data more secure, then compile your game data file with:

 


luac -o game.cdata game.data

 

your data are in binary format now, and simply change loading to GameData = dofile("game.cdata").

 

Note: Compiled data are good only for static data like startup setting, scene properties, addons, items descr., ...

  • Upvote 1

[HW] C2D Q6600, 4GB RAM, NV8800GTX, Vista Ultimate x64

[sW] Blide Plus, BlitzMax, Delphi, C++, 3DWS 5.53, Leadwerks 2.xx

 

76561197970156808.pngAndyGFX.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...