Game Development Community

Game State - strategy for tracking game state in script

by EddieRay · in Torque Game Engine · 04/22/2005 (10:36 am) · 2 replies

From what I've been learning with TGE scripting... it is possible to use the SendServerMessage() and SendClientMessage() script commands (the names might be wrong - I can't remember them exactly... so many commands!) to basically pass anything you want (as long as it's a simple string message) between the client<==>server.

I was thinking that this kind of approach could be used as a mechanism to store game "state" (like how many times the player has entered a building, how much gold they've collected, what items they are carrying, who the player is talking to, what quests the player has completed, etc.)... basically, to be used for all the other things besides health, energy, ammo, etc., that are already tracked/handled/accessible in TGE script/C++ code. Any game state that could be handled by passing text messages should work... right?

So, the question that comes to my mind is, where should I "hang" this data in the server, and where should I "hang" it on the client. I'm thinking that on the client, I could just add the fields dynamically to the Player object using something like:

%player.mydata["quest1"] = "done"

... and this would likely be in response to a server message coming in that says "set quest1 done" or whatever.

However, I'm not sure where to keep the data on the server side... maybe on the GameConnection object? Then I could potentially save it to a file whenever the player disconnects?

#1
04/22/2005 (12:31 pm)
Yes, the GameConnection (%client/%conn, depending on which script you happen to be in) is probably a very good place to store this, per player.

If you are talking single player games only, you could always just make it a global variable ($Server::GameStateData::MyVariableHere, or something similar).
#2
04/22/2005 (1:06 pm)
Thanks Stephen!