Script not working

Discussion in 'Modifications' started by Stubbsy, Jun 16, 2015.

  1. Stubbsy

    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: Jun 16, 2015
  2. 57thEnryu

    57thEnryu Member

    so you are making a script that says "foo" every time you llama the flag?

    ok then....
     
  3. Stubbsy

    Stubbsy Contributor

    Clearly not...
     
  4. Belberith

    Belberith Legions Developer

    echo($a2

    Should be %a2
     
  5. Stubbsy

    Stubbsy Contributor

    Yeah, I changed that. It's still displaying 0 for some reason..
     
  6. 57thEnryu

    57thEnryu Member

    oh I see, nvm (not the best with code...)
     
  7. Stubbsy

    Stubbsy Contributor

    Lol no worries!
     
  8. Belberith

    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.
     
  9. Stubbsy

    Stubbsy Contributor

    Thanks for that, but, now it's not echoing out anything at all in the console.

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

     
    Last edited: Jun 16, 2015
  10. Belberith

    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 likes this.
  11. Stubbsy

    Stubbsy Contributor

    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?
     
  12. Belberith

    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.
     
  13. Stubbsy

    Stubbsy Contributor

    Got you. Thanks!