Game Development Community

Update the field of a GUI from inside the server

by Isidoros · in Torque Game Engine · 11/14/2009 (12:23 pm) · 4 replies

Lets say I have the next GUI object in a script in the CLIENT folder:
new GuiMLTextCtrl(DisplayKits) {
      horizSizing = "right";
      vertSizing = "top";
      position = "157 -70";
      minExtent = "8 8";
      visible = "0";
      helpTag = "0";
      allowColorChars=0;
      text = $MLfont@"0";
      wrap = "0";
   };
I want to update the "text" field during the game.

What I have done and it works is:
function GameConnection::updateDisplayKits(%this,%numOfKits)
{
	%updatedText=$MLfont@%numOfKits;
	DisplayKits.setText(%updatedText);
}

The above part of script is located in game.cs in the SERVER folder. Is the above the most suitable way to update the text field or I have to use the commandToClient method and a clientCmdDoSmt function??

#1
11/14/2009 (1:37 pm)
Quote:or I have to use the commandToClient method and a clientCmdDoSmt function??

If your project is purely single-player, then technically there's nothing to stop you from updating a gui directly from a server script. However, if you are at all concerned about multiplayer compatibility, then you'll want to run that through a commandToClient/clientCmd function.
#2
11/14/2009 (2:13 pm)
Scott is right. But for the sake of working with the framework, I would recommend to use the client/server callbacks, even if the game is single player.
#3
11/15/2009 (3:43 am)
You should have a SimGroup called ClientGroup. In this group are all id's of all connected clients. In a multiplayer game i would recommend to use CommandToClient/CommandToServer. This way you can send all clients (or only a few) a command.
#4
11/15/2009 (11:25 am)
Thanks for the tips ;)