Player variables: help please
by Tyler Pfaff · in Technical Issues · 10/11/2004 (7:28 am) · 4 replies
I'm having some difficulty getting player variables to set correctly. We are working on a networked FPS game for a class project and I've added a taunt variable to the playerbody datablock in player.cs. This variable rises when a player kills someone and performs a taunt.
I'm currently updating the variable like so:
%sourceClient.player.TauntBonusUp();
%this.player.TauntBonusDown();
Those calls come towards the end of the OnDeath() in game.cs. The actual functions reside in player.cs and look like this:
function Player::TauntBonusUp(%this)
{
%taunttemp = %this.getDataBlock().TauntBonus;
if( %taunttemp < 5)
{
%this.getDataBlock().TauntBonus = %taunttemp + 1;
}
}
function Player::TauntBonusDown(%this)
{
%tauntdown = %this.getDataBlock().TauntBonus;
if( %tauntdown >= 1)
{
%this.getDataBlock().TauntBonus = %tauntdown - 1;
}
}
The problem is that all players somehow end up sharing the same TauntBonus. So, any time a player kills and celebrates, all players' TauntBonus variable rises. Can someone tell me how to make it so that only the person who got the kill receives the bonus?
Thanks
I'm currently updating the variable like so:
%sourceClient.player.TauntBonusUp();
%this.player.TauntBonusDown();
Those calls come towards the end of the OnDeath() in game.cs. The actual functions reside in player.cs and look like this:
function Player::TauntBonusUp(%this)
{
%taunttemp = %this.getDataBlock().TauntBonus;
if( %taunttemp < 5)
{
%this.getDataBlock().TauntBonus = %taunttemp + 1;
}
}
function Player::TauntBonusDown(%this)
{
%tauntdown = %this.getDataBlock().TauntBonus;
if( %tauntdown >= 1)
{
%this.getDataBlock().TauntBonus = %tauntdown - 1;
}
}
The problem is that all players somehow end up sharing the same TauntBonus. So, any time a player kills and celebrates, all players' TauntBonus variable rises. Can someone tell me how to make it so that only the person who got the kill receives the bonus?
Thanks
About the author
#2
10/11/2004 (9:53 am)
Yep, that fixed it. Thanks for the help. Ha, I just wish I'd asked sooner, I've been working on this for awhile now.
#3
I am having a similiar issue although it involves guiTextCtrl's variable field. I have added some stat variables to the players (they appear in the players description in the tree(); box) but i dont know what to use in the varible box to get them to update.
I have gone into the tree and gotten the id of my character and the boxes display the appropriate info when i use
1524.int
but not always is it the same. ive tried
%sourceClient.player.int
%sourceClient.int
%client.int
%client.player.int
%player.int
and none work. What is the actual variable i need to use to access each individual characters int variable for use in the text control?
03/03/2005 (1:05 am)
I appologize in advance for A) bringing back an old topic, B) posting a quesiton in someone elses thread ;)I am having a similiar issue although it involves guiTextCtrl's variable field. I have added some stat variables to the players (they appear in the players description in the tree(); box) but i dont know what to use in the varible box to get them to update.
I have gone into the tree and gotten the id of my character and the boxes display the appropriate info when i use
1524.int
but not always is it the same. ive tried
%sourceClient.player.int
%sourceClient.int
%client.int
%client.player.int
%player.int
and none work. What is the actual variable i need to use to access each individual characters int variable for use in the text control?
#4
To get it updating forever, you can use a schedule that calls setText() every 64 milliseconds or so.
03/04/2005 (9:21 am)
The guiTextCtrl will not keep monitoring the variable for changes, I think. It will only read the variable's content upon intialization.To get it updating forever, you can use a schedule that calls setText() every 64 milliseconds or so.
Torque Owner Davide Archetti
Default Studio Name
You know, somewhere in your code you have
%player = new Player() { dataBlock = BattleArmorCmdDefault; client = %this; };To add a new variable that is assigned only to that player, just do something like
You don't need to declare the variable somewhere, just define it and then use it