| Blockland Forums > Modification Help |
| [MOAR PROBLEMS]My Gui Won't Read a Variable |
| << < (2/3) > >> |
| brickybob:
--- Quote from: xXBeibsFan119Xx on April 25, 2012, 11:10:57 PM ---Mind sharing? --- End quote --- I changed it a bit since this post, but here --- Code: ---function STATFUNCTION(%cl) { %radiation = 33; stat1.setValue(%radiation); if(%radiation > 25) { radiationtimer(%cl); } } --- End code --- |
| M:
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: ---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"); } } --- End code --- Clientside code: This only updates the GUI object based on a value the server tells the client. --- Code: ---function clientCmdstalker_updateRads(%rads) { stat1.setValue(%rads); } --- End code --- Always make this distinction - the server.cs and client.cs files are separate for a reason. |
| brickybob:
--- Quote from: M on April 27, 2012, 08:10:41 AM ---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: ---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"); } } --- End code --- Clientside code: This only updates the GUI object based on a value the server tells the client. --- Code: ---function clientCmdstalker_updateRads(%rads) { stat1.setValue(%rads); } --- End code --- Always make this distinction - the server.cs and client.cs files are separate for a reason. --- End quote --- --- Code: ---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); } --- End code --- And after typing /ss my gui is blank. I put the other part in client.cs, btw. |
| elm:
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); } |
| Nexus:
or commandToAll('cmd', %data); |
| Navigation |
| Message Index |
| Next page |
| Previous page |