Problems with messageAll
by Peder Husom · in Torque 3D Beginner · 05/15/2011 (3:17 pm) · 8 replies
Hi
Im trying to send a string with messageAll. Serverside the code looks like this
on the client I got this;
put it seems to only print
"Kill Notice: 2 ZMsgClientKilled"
in the console :s
And why can't I use this serverside(tried it earlier):
messageAll('ZMsgClientKilled', %client.playerName, %sourceObject.playerName, %damageType);
And a last question;
- %client is the one getting killed
- %sourceObject is the killer
right?
Im trying to send a string with messageAll. Serverside the code looks like this
// ZM :: Kill notice
switch$( %damageType )
{
case "Suicide":
%killString = %client.playerName @ " commited suicide!";
case "RocketDamage":
%killString = %sourceClient.playerName @ " blew up " @ %client.playerName @ " with a rocket launcher!";
}
messageAll('ZMsgClientKilled', %killString);on the client I got this;
addMessageCallback('ZMsgClientKilled', zmHandleClientKilled);
function zmHandleClientKilled(%killString)
{
echo(" :: ZM Client :: ");
echo(" Kill Notice: " @ %killString );
}put it seems to only print
"Kill Notice: 2 ZMsgClientKilled"
in the console :s
And why can't I use this serverside(tried it earlier):
messageAll('ZMsgClientKilled', %client.playerName, %sourceObject.playerName, %damageType);
And a last question;
- %client is the one getting killed
- %sourceObject is the killer
right?
#2
This is how I send it:
and this is the client-side script:
Problem is that is still just prints (on the 3th echo)
Kill Notice: 2 ZMsgKillNotification
05/19/2011 (1:44 pm)
Okey, still having some problems with this.. This is how I send it:
case "Suicide":
messageAll('ZMsgKillNotification', "%1 committed suicide!", %client.playerName);
case "RocketDamage":
messageAll('ZMsgKillNotification', "%1 blew up %2 with a rocket launcher!", %sourceClient.playerName, %client.playerName);
default:
messageAll('ZMsgKillNotification', "%1 killed %2", %sourceClient.playerName, %client.playerName);and this is the client-side script:
addMessageCallback('ZMsgKillNotification', zmHandleClientKilled);
function zmHandleClientKilled(%killString)
{
echo(" :: ZM Client :: ");
echo(" Kill Notification recived! ");
echo(" Kill Notice: " @ %killString );
}Problem is that is still just prints (on the 3th echo)
Kill Notice: 2 ZMsgKillNotification
#3
The addMessageCallback is superfluous in this context but is echo'ing correctly given the body of your function. The first argument in the handleFunction() is always the messageType, which is what you're echo'ing, regardless of what you label that argument. The 'kill' or message string will be the 2nd argument. You will also need to use additional arguments to successfully fill in the parameter based messages since concatenated messages are not sent in full.
05/19/2011 (2:42 pm)
You're still trying to pass quote strings for your messageString, they need to be tagged strings, eg single quotes in order to show up correctly in the chatHud.The addMessageCallback is superfluous in this context but is echo'ing correctly given the body of your function. The first argument in the handleFunction() is always the messageType, which is what you're echo'ing, regardless of what you label that argument. The 'kill' or message string will be the 2nd argument. You will also need to use additional arguments to successfully fill in the parameter based messages since concatenated messages are not sent in full.
addMessageCallback('ZMsgKillNotification', zmHandleClientKilled);
function zaHandleClientKilled(%msgType, %MsgString)
{
echo("Kill string is: "@ %msgString);
}Also be aware that anytime a messageCallback type/string is echo'd a number will also appear preceding the message - maybe this number represents the tagged index, I'm not sure.
#4
Cause I want to send
1. player name of the one getting killed (Can I just send this as an ID then have the client look up its name? Like %clients[clientIDRecived].playerName?)
2. player name of the killer
3. a weapon ID for the weapon used
05/19/2011 (3:33 pm)
Hm-m.. Okey, so if I want to send something with parameters I guess I should stick with commandToClient? Cause I want to send
1. player name of the one getting killed (Can I just send this as an ID then have the client look up its name? Like %clients[clientIDRecived].playerName?)
2. player name of the killer
3. a weapon ID for the weapon used
#5
Perhaps if I knew what purpose your message callback is meant to have I could offer more help. For simple death messages that show up in chat you don't need the callbacks.
05/19/2011 (3:48 pm)
Just add the parameters to your function definition. If messageAll(), messageClient(), etc know the parameters then the messageCallbacks know them as well. But if you're not listing them as part of the function definition then they might as well not exist.function clientCmdServerMessage(%msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
{
// Get the message type; terminates at any whitespace.
%tag = getWord(%msgType, 0);
// First see if there is a callback installed that doesn't have a type;
// if so, that callback is always executed when a message arrives.
for (%i = 0; (%func = $MSGCB["", %i]) !$= ""; %i++)
{
call(%func, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10);
}
// Next look for a callback for this particular type of ServerMessage.
if (%tag !$= "")
{
for (%i = 0; (%func = $MSGCB[%tag, %i]) !$= ""; %i++)
{
// This line prepares the callback and it's argument list.
call(%func, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10);
}
}
}When you define/declare your callback, just include the additional paramters as well:messageAll('ZMsgKillNotification', "%1 killed %2", %sourceClient.playerName, %client.playerName);
addMessageCallback('ZMsgKillNotification', zmHandleClientKilled);
// what you name the arguments here does not matter. Only that the body of the function uses the same argument names.
function zaHandleClientKilled(%msgType, %MsgString, %param1, %param2)
{
// %msgString = the message
// %param1 = 1st argument used to fill in the message, in this case the killer (%sourceClient.playerName as processed from messageAll)
// %param2 = 2nd arugment used to fill in the message, in this case the one killed (%client.playerName as processed from messageAll)
echo("Kill string is: "@ %msgString);
}Perhaps if I knew what purpose your message callback is meant to have I could offer more help. For simple death messages that show up in chat you don't need the callbacks.
#6
Serverside
then on the client I can do like this
EDIT:
That kinda works, still getting numbers(atm im getting 17) in front of the names. And they are colored, how can I remove that?
05/20/2011 (4:31 am)
So I can do like this:Serverside
messageAll('KillNotification', %sourceClient.playerName, %client.playerName, %weaponId);then on the client I can do like this
addMessageCallback('KillNotification', handleKillNotification);
function handleKillNotification(%msgType, %killer, %target, %weaponid)
{
// switch-case and parsing
}EDIT:
That kinda works, still getting numbers(atm im getting 17) in front of the names. And they are colored, how can I remove that?
#7
The numbers in front of the names, as I already mentioned, appear to be the function tag/index of the callback as processed by the methods in message.cs if used to display a message constructed from the arguments passed. I haven't looked into preventing the tag from displaying since my messages go through the chatHud, and my callbacks are used as event handlers.
05/20/2011 (5:53 pm)
Don't forget that the %msgString, or tagged message string, should be the 2nd argument -- unless you are you wanting to totally bypass the stock chathud and write you own messageHud kind of thing? That's the impression I'm gathering from your examples.The numbers in front of the names, as I already mentioned, appear to be the function tag/index of the callback as processed by the methods in message.cs if used to display a message constructed from the arguments passed. I haven't looked into preventing the tag from displaying since my messages go through the chatHud, and my callbacks are used as event handlers.
#8
Okey, diden't know about the index of functions now, but as I watch the console I see the "mapping 'FunctionName' to index X".
I'll dig around in the chatHud and see if I can come up with anything.
05/21/2011 (8:28 am)
"write you own messageHud kind of thing?" Exactly! Okey, diden't know about the index of functions now, but as I watch the console I see the "mapping 'FunctionName' to index X".
I'll dig around in the chatHud and see if I can come up with anything.
Associate Michael Hall
Distracted...
switch$ (%damageType) { case "Impact": messageAll('MsgDeath', '%1 flew well but landed poorly.', %client.name); case "Fire": messageAll('MsgDeath', '%1 was burned to a crisp.', %client.name); case "Suicide": messageAll('MsgDeath', '%1 took the easy way out.', %client.name); default: messageAll('MsgDeath', '%1 was killed by %2.', %client.name, %sourceObject.name); }Parameters to use go inside the tagged string, with %1 being the first argument after the string, %2 being the second argument, etc, etc.On your addMessageCallback: Your callback is only parsing the first argument there which is the tagged string that should indicate the messageType. Instead of a messageType followed by a messageString it is passing the messageType tag as the string to display due to incorrect usage of server message code to send a client callback. The callback is a secondary benefit of the message system that allows a certain type of message to trigger certain events. Given the body of the callback function it's actually echo'ing correctly.
About the serverside question: that fails due to not passing an actual message string as the message system expects. It's probably working but since 'ZMsgClientKilled' is the messageType and is followed only by a list of arguments it has no message to process which means nothing to display. The message system handles getting things from the server to each client if the expected format is followed.
On the last question, you are correct.