Author Topic: How the hell do I fix this syntax  (Read 1030 times)

So, I've been trying to get into torquescript recently, and wanted to make a little script to roll a dice with a max output defined by the user, but I kept having problems with the script:
Code: [Select]
function servercmdRoll(%maxvalue)
{
%output = getrandom(1,%maxvalue);
messageClient(%client,"","has rolled"@ %output @"out of"@ %maxvalue @"!"*");
}
When I start a single player server, the game flips out and refuses to load it, giving me this:
Code: [Select]
Loading Add-On: Script_Roll (CRC:1566994399)
Add-Ons/Script_Roll/server.cs Line: 4 - Syntax error.
>>> Some error context, with ## on sides of error halt:
unction servercmdRoll(%maxvalue)

{

^%output = getrandom(1,%maxvalue);

^messageClient(%client,"","has rolled"@ %output @"out of"@ %maxvalue @"!"*");
##
##};
>>> Error report complete.

ADD-ON "Script_Roll" CONTAINS SYNTAX ERRORS
There's nothing where the error halt is.
What'd I do wrong/how do I fix this?

also, is there a better way to print the output?I've basically just been looking at snippets of other scripts that have outputs like this and I get the feeling there's a better way to do this.
(also i want to make it message all(i tried announce(%1"","has rolled"@ %output @"out of"@ %maxvalue @"!"*") but I wasn't sure if using %1 would output it correctly, so i changed it to messageClient and used %client instead just so i could make sure it worked first))

The problem is at the very end of messageClient:
"!"*"

also, is there a better way to print the output
messageClient(%client,'','%1 has rolled %2 out of %3',%client.getPlayerName(),%output,%maxvalue);

The problem is at the very end of messageClient:
"!"*"
I had tried taking out the *" bit earlier, but it gave me the same exact error without it, which is why I had added it.

messageClient(%client,'','%1 has rolled %2 out of %3',%client.getPlayerName(),%output,%maxvalue);
Code: [Select]
Add-Ons/Script_Roll/server.cs (0): Unable to find object: '' attempting to call function 'getPlayerName'
BackTrace: ->servercmdRoll

Code: [Select]
Add-Ons/Script_Roll/server.cs (0): Unable to find object: '' attempting to call function 'getPlayerName'
BackTrace: ->servercmdRoll
oh you don't have %client in the arguments

function servercmdRoll(%client, %maxvalue)
{
     //stuff
}

ah, that explains it. I thought the arguments for the function were just for player inputs.

ah, that explains it. I thought the arguments for the function were just for player inputs.

Nah. The first argument for all server commands is the client object that sent the command.

Also, instead of messageClient(%client,"",...
You'd use messageClient(%client,'',...

Single Quotes.

The problem is at the very end of messageClient:
"!"*"
messageClient(%client,'','%1 has rolled %2 out of %3',%client.getPlayerName(),%output,%maxvalue);

Oooh you can use %x for other variables? Sweet.

Oooh you can use %x for other variables? Sweet.
Only in tagged strings, the ones that use single quotes.

Also, instead of messageClient(%client,"",...
You'd use messageClient(%client,'',...

Single Quotes.

Technically it doesn't really matter. Yes, that field accepts a tagged string, but passing a null value ("" or 0) works just fine. It only becomes an issue if they try something like "msgAdminForce".