Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
guidelines:adding_message_to_gamebots [2012/02/08 16:59]
martin.cerny
guidelines:adding_message_to_gamebots [2012/02/08 21:29]
martin.cerny
Line 62: Line 62:
 <code> <code>
 static function SendNotifyMessage(){ static function SendNotifyMessage(){
- local Controller C; 
- local GBClientClass G; 
- local string message; 
- local WorldInfo worldInfo; 
-  
- worldInfo = class'WorldInfo'.static.GetWorldInfo(); 
- 
  message = "MYMESSAGE {StringParam bagr}";  message = "MYMESSAGE {StringParam bagr}";
  
- foreach worldInfo.AllControllers(class'Controller', C) +        SendMessageToAll("MYMESSAGE {StringParam bagr}"); 
- { +        SendMessageToAllBots("BOTMESSAGE {IntParam 23}"); 
- if( C.IsA('RemoteBot') ) +        SendMessageToAllControlConnections("CONTROLMESSAGE {FloatParam 1.5}");
-+
- RemoteBot(C).myConnection.SendLine(message); +
- +
-+
- +
-    if (GBGameInterface(worldInfo.Game).GetGameHandler().theControlServer != None) +
- { +
- for (G = GBGameInterface(worldInfo.Game).GetGameHandler().theControlServer.ChildListG != None; G = G.Next ) +
- { +
- G.SendLine(message); +
-+
- }+
  
 } }
  
 </code> </code>
-This method sends the message to all bot and control server connections.+This method sends the one message to all bot and control server connections, another only to all bots and yet another only to control connections. Note that while this method is quite simple it is good practice not to embed this in your action code, but keep it in the connection class so that the vocabulary of gamebots commands and messages is not scattered in many classes. 
 + 
 +Of course you might want to have a message that is sent for example only to the bot that triggered something. Than you need to get the bot object from the event and use it's connection.
  
 ====== Receiving commands from Pogamut ====== ====== Receiving commands from Pogamut ======
Line 179: Line 162:
 The ConnectionClass is a string containing fully qualified name of the connection class. If you are not trying to achieve something complicated, it is usually good idea to add your extension classes to GameBotsUDK package, since it does not require to modify any other ini file (adding a package requires you to modify some of the files that are modified by gamebots, so that could lead to some trouble with synchronizing your extension development with the main gamebots extension). The ConnectionClass is a string containing fully qualified name of the connection class. If you are not trying to achieve something complicated, it is usually good idea to add your extension classes to GameBotsUDK package, since it does not require to modify any other ini file (adding a package requires you to modify some of the files that are modified by gamebots, so that could lead to some trouble with synchronizing your extension development with the main gamebots extension).
  
-If you have done that, try running UDK with GameBots as usual you should see "Using YOURCLASS for connection" in the UDK log. If you are not, something is wrong.+If you have done that, try running UDK with GameBots as usual you should see "Using YOURCLASS for bot connection" in the UDK log. If you are not, something is wrong
 + 
 +In a similar way you can replace the default implementation of ControlConnection to parse custom messages. You extend the ControlConnection class, override ProcessRegularAction there, create file called DefaultControlServer.ini and specify your class's name in the ConnectionClass property.
  
guidelines/adding_message_to_gamebots.txt · Last modified: 2012/02/08 21:34 by martin.cerny