Author Topic: [MOAR PROBLEMS]My Gui Won't Read a Variable  (Read 1072 times)

http://dl.dropbox.com/u/38907569/RP_Stalker.zip

Pretty obvious what I'm trying to do just by looking at the file name.

Anyways, when I open the gui the spot where the rads value is always blank, not sure where I messed up so I submitted the whole thing.

Any ideas?
« Last Edit: April 27, 2012, 01:05:49 PM by brickybob »

%cl.rads Is blank client sided. You need the server to tell you how many %cl.rads you have.

You should have the server do commandToClient(GuiStatsUpdate, %client.rads); and then have something like this:
Code: [Select]
function clientCmdGuiStatsUpdate(%rads)
{
radsstat.setValue(%rads);
}
« Last Edit: April 25, 2012, 07:28:31 PM by jes00 »

when does GuiStatsUpdate get called?  I don't see anything calling it in this script.

I got it sorted out now, but thanks anyways.


Mind sharing?
I changed it a bit since this post, but here
Code: [Select]
function STATFUNCTION(%cl)
{
%radiation = 33;
stat1.setValue(%radiation);
if(%radiation > 25) {
radiationtimer(%cl);
}
}

nononono

The GUI is client sided, these things should be server sided. What jes00 said is correct - you need to use a clientcmd to update the GUI. Your current solution may work in singleplayer but it won't work on a dedicated even for the first client, and it'll spam your console because stat1 doesn't exist. Or if it does you are horrid and have instantiated a gui object serverside. Don't do that.

Serverside code: This does all the actual work and lets the client know what's going on.
Code: [Select]
function Player::setRads(%player,%rads)
{
   %player.rads = %rads;
   cancel(%player.radSched);
   if(%rads > 25)
   {
      %player.radSched = %player.schedule(10000,"takeRadDamage");
   }
   commandToClient(%player.client,'stalker_updateRads',%rads);
}
function Player::takeRadDamage(%player)
{
   cancel(%player.radSched);
   // This function would damage the player based on their rads or whatever here.
   // %player.damage should automatically 'kill' the player if their health falls too so that shouldn't be an issue for this next part:
   // Only continue to take rad damage if you aren't already dead. Not sure that's right, but I think it is.
   if(%player.getState() !$= "Dead")
   {
      %player.radSched = %player.schedule(10000,"takeRadDamage");
   }
}

Clientside code: This only updates the GUI object based on a value the server tells the client.
Code: [Select]
function clientCmdstalker_updateRads(%rads)
{
   stat1.setValue(%rads);
}

Always make this distinction - the server.cs and client.cs files are separate for a reason.

nononono

The GUI is client sided, these things should be server sided. What jes00 said is correct - you need to use a clientcmd to update the GUI. Your current solution may work in singleplayer but it won't work on a dedicated even for the first client, and it'll spam your console because stat1 doesn't exist. Or if it does you are horrid and have instantiated a gui object serverside. Don't do that.

Serverside code: This does all the actual work and lets the client know what's going on.
Code: [Select]
function Player::setRads(%player,%rads)
{
   %player.rads = %rads;
   cancel(%player.radSched);
   if(%rads > 25)
   {
      %player.radSched = %player.schedule(10000,"takeRadDamage");
   }
   commandToClient(%player.client,'stalker_updateRads',%rads);
}
function Player::takeRadDamage(%player)
{
   cancel(%player.radSched);
   // This function would damage the player based on their rads or whatever here.
   // %player.damage should automatically 'kill' the player if their health falls too so that shouldn't be an issue for this next part:
   // Only continue to take rad damage if you aren't already dead. Not sure that's right, but I think it is.
   if(%player.getState() !$= "Dead")
   {
      %player.radSched = %player.schedule(10000,"takeRadDamage");
   }
}

Clientside code: This only updates the GUI object based on a value the server tells the client.
Code: [Select]
function clientCmdstalker_updateRads(%rads)
{
   stat1.setValue(%rads);
}

Always make this distinction - the server.cs and client.cs files are separate for a reason.
Code: [Select]
function Player::setRads(%player,%rads)
{
   %player.rads = %rads;
   cancel(%player.radSched);
   if(%rads > 25)
   {
      %player.radSched = %player.schedule(10000,"takeRadDamage");
   }
   commandToClient(%player.client,'stalker_updateRads',%rads);
}
function Player::takeRadDamage(%player)
{
   cancel(%player.radSched);
   // This function would damage the player based on their rads or whatever here.
   // %player.damage should automatically 'kill' the player if their health falls too so that shouldn't be an issue for this next part:
   // Only continue to take rad damage if you aren't already dead. Not sure that's right, but I think it is.
   if(%player.getState() !$= "Dead")
   {
      %player.radSched = %player.schedule(10000,"takeRadDamage");
   }
}
function serverCMDss(%client)
{
    %client.player.rads = 0;
    commandToClient(%client,'stalker_updateRads',%player.rads);
}

And after typing /ss my gui is blank.

I put the other part in client.cs, btw.

You're doing something wrong. It should look like so:

//This would be in the server.cs or any server sided code
function sendDataToAllClients(%data)
{
   for(%i=0;%i<clientGroup.getCount();%i++)
   {
      %c = clientGroup.getObject(%i);
      
      //command to the client, to catch the data
      commandToClient(%c,'catchData',%data);
   }
}

//This goes to the client.cs or any client sided code
function clientCmdCatchData(%data)
{
   //do something with our data
   echo("Data caught: "@%data);
   someGuiTextCtrl.setText(%data);
}

or

commandToAll('cmd', %data);

or

commandToAll('cmd', %data);

They say you learn something new everyday....

Quote
function serverCMDss(%client)
{
    %client.player.rads = 0;
    commandToClient(%client,'stalker_updateRads',%player.rads);
}
Bolded your issue