Script not working

Stubbsy

Contributor
Slowly but surely getting there, but needing some help.

I've created this:
Code:
addMessageCallback("MsgCtfLlamaGrab", foo);

function foo (%msgType, %msgString, %a1, %a2) {
    echo($a2 + " Llama grabbed " + %a1 + "'s flag");
    echo("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
}

It's displaying "0"...
 
Last edited:

Belberith

Legions Developer
Oh right, I'd forgotten that TorqueScript deals with strings differently than an actual programming language.
%a2 + " Llama grabbed " + %a1 + "'s flag"
This will literally add the values of the numbers or strings converted to numbers, and any string in TS is numerically equivalent to 0. The concatenate symbol is @, so it should look like this:
%a2 @ " Llama grabbed " @ %a1 @ "'s flag"
SPC and TAB are other concatenation keywords, inserting a space or a tab respectively.
 

Stubbsy

Contributor
Oh right, I'd forgotten that TorqueScript deals with strings differently than an actual programming language.
%a2 + " Llama grabbed " + %a1 + "'s flag"
This will literally add the values of the numbers or strings converted to numbers, and any string in TS is numerically equivalent to 0. The concatenate symbol is @, so it should look like this:
%a2 @ " Llama grabbed " @ %a1 @ "'s flag"
SPC and TAB are other concatenation keywords, inserting a space or a tab respectively.
Thanks for that, but, now it's not echoing out anything at all in the console.

addMessageCallback("MsgLlamaCtfGrab", foo);

function foo (%msgType, %msgString, %a1, %a2) {
echo(%a1 @ " flag has been Llama'd by " @ %a2);
echo("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
}

I also tried concatenating with a comma, using detag and stripping color, but it still doesn't display anything.

addMessageCallback("MsgLlamaCtfGrab", foo);

function foo (%msgType, %msgString, %a1, %a2) {

%teamName = textFormat(%a1);

echo(%teamName @ " flag has been Llama'd");
echo("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
}

function textFormat (%a1) {
return stripColorCodes(replaceTeamStrings(detag(%a1)));
}
 
Last edited:

Belberith

Legions Developer
Your exact code prints stuff fine for me (you'll want to use detag and replaceTeamStrings though). I put it in client/scripts/message.cs.
 

Stubbsy

Contributor
Your exact code prints stuff fine for me (you'll want to use detag and replaceTeamStrings though). I put it in client/scripts/message.cs.
Thanks for your help. I was writing the script in "autoexec" folder all along. But why didn't it work anyway in the autoexec folder?
 

Belberith

Legions Developer
No prob. It didn't work there because the client/scripts path is executed after the mods/autoexec path, so the addMessageCallback functionality doesn't exist yet when called in a mods/autoexec file.
 
Top