RPG Stats and datablock PlayerData()
by Jon Ray · in Torque 3D Beginner · 01/20/2010 (12:37 am) · 6 replies
So I take it that most of the player's controls are listed under datablock PlayerData(). With this in mind I was wondering how those of you working on a stand alone RPG handle the additional RPG stats for a PC (Player Character)? Do you just add all the data to PlayerData() or do you use global variables? Also, for persistence, how are the stats being saved so that a player may load their data back into the PlayData() once the game has been restarted?
I just want to get some design ideas before going to far down this road.
I just want to get some design ideas before going to far down this road.
About the author
Independent Filmmaker / Game Developer.
#2
01/20/2010 (2:07 am)
Thanks for the input, I would never think to base an NPC class off of PlayerData, I'd just create a new datablock NPC() for that. In regards to attachment to %client or %client.player could you give a sudo or brief sample script of how you would do something like this?
#3
True, but then if you have two NPCs running off of one datablock and one needs to change a field to be unique from the other, then both change, which is why I mentioned that. What you probably want to do is decide which variables will be unique to a single player or NPC and which should be in the datablocks, and that would probably work best.
Now, it should be noted that the above is done on the server side, and the client side should only be a "viewer" for information, so when my player's healthbar isn't updated unless it gets into combat and then the bars are updated as a part of the resolution of actions. Same goes for inventory and whatnot- data only gets pulled when the client asks for something, and it never has the ability to tell the server what the information is. Rather, it only tells the server what the player is trying to do.
For a single-player game, you should be fine with the above, as I have a single-player demo I'm working on now that has the %player holding some variables. Really depends on how you're using them and where.
01/20/2010 (12:38 pm)
Quote:Thanks for the input, I would never think to base an NPC class off of PlayerData, I'd just create a new datablock NPC() for that.
True, but then if you have two NPCs running off of one datablock and one needs to change a field to be unique from the other, then both change, which is why I mentioned that. What you probably want to do is decide which variables will be unique to a single player or NPC and which should be in the datablocks, and that would probably work best.
Quote:In regards to attachment to %client or %client.player could you give a sudo or brief sample script of how you would do something like this?
function playerLoad(%client)
{
%player = %client.player;
%player.curHealth = //Wherever you get the data from
%player.maxHealth = //Wherever you get the data from
}Now, it should be noted that the above is done on the server side, and the client side should only be a "viewer" for information, so when my player's healthbar isn't updated unless it gets into combat and then the bars are updated as a part of the resolution of actions. Same goes for inventory and whatnot- data only gets pulled when the client asks for something, and it never has the ability to tell the server what the information is. Rather, it only tells the server what the player is trying to do.
For a single-player game, you should be fine with the above, as I have a single-player demo I'm working on now that has the %player holding some variables. Really depends on how you're using them and where.
#4
01/20/2010 (9:01 pm)
Datablocks are for static information that doesn't need to change over the course of a game. For everything else, I'd use object properties, like Ted suggested. Global variables are messy ;)
#5
01/21/2010 (9:19 pm)
I added mine to both the Player class and the PlayerData class, and initialized the ones on the player class from the datablock. Then, you can modify them to your hearts content on the Player.
#6
01/23/2010 (8:12 am)
Sounds reasonable! That way you have some sort of 'default' values which you can apply changes to.
Torque 3D Owner Ted Southard
I would do neither. Using PlayerData can be a problem if you base NPCs off of that (PlayerData is shared, so any changes change everyone who uses it), and using a global might make it easier to hack (though, if it's single-player, that argument is probably not as valid). You can attach it to the %client, or %client.player, though, and get the behavior you want.
As for saving/loading, you want to look at FileObject(), .openForWrite(), .openForRead(), .writeLine(), .readLine(), and all those goodies, and you can save and load files for whatever you need.