Author Topic: Variables that rely on user imput defaulted to numbers?  (Read 3102 times)

Hey Forums, I've been having an annoying problem in my scripts lately. I was making one where I could write/read text files on my computer through the game, but I noticed a strange problem. Every time I would input the variable that would end up acting as the directory to write to ( /writeto Add-Ons/script...ect) the variable would default to the numerical value of 8282. I also noticed this took effect on other scripts of mine. In it's simplest form, here it is:

function servercmdGlitch(%input)
{
   announce(%input);
}

Ingame, it'd announce, "8282". If I remember correctly, there was also another number showing up on other scripts of mine. I've tried changing text editors and encryption methods. Does anyone know the problem?

8282 is the ID of the client that used the /glitch command in that case.


function serverCmdGlitch(%client, %input)
                         ^~~~~~~~~
{
    announce(%input);
}

Expanding on what Port said, the number is the ID associated with the GameConnection object that called the serverCmd.

If you're trying to get the name of the client, you can use %client.getPlayerName().

Server commands' first argument is always the client that's calling it. If you want the user to provide input, you add arguments afterwards.

Expanding on what Port and otto-san said
Each word is(typically) another argument. So if I said "/glitch I love pickles" in the chat, it'd call serverCmdGlitch(%client, %a, %b, %c); and %a would be I, %b would be love, and %c would be pickles.
The only case where this is not so is if the client manually puts the following in their console or if the following is ran by a client sided script(same thing): commandToServer('glitch', "I love pickles", "so much", "that I could die"); In this case %a would be I love pickles, %b would be so much, and %c would be that I could die.

Expanding on what Port, otto-san, and jes00 said
Due to each word being an argument to chat commands add-ons that want the string of words used after the command will usually use numbers and a for loop. This would be an example:
Code: [Select]
function serverCmdGlitch(%client,%arg1,%arg2,%arg3,%arg4,%arg5,%arg6,%arg7,%arg8,%arg9,%arg10,%arg11)
{
   for(%i=0;%i<11;%i++)
      %string = %arg[%i];
   announce(%sring);
}

Due to each word being an argument to chat commands add-ons that want the string of words used after the command will usually use numbers and a for loop. This would be an example:
Code: [Select]
function serverCmdGlitch(%client,%arg1,%arg2,%arg3,%arg4,%arg5,%arg6,%arg7,%arg8,%arg9,%arg10,%arg11)
{
   for(%i=1;%i<12;%i++)
      %string = %string SPC %arg[%i];
   announce(trim(%string));
}
ftfy

edit: no idea how that happened thor :(
« Last Edit: January 02, 2015, 08:54:38 PM by Ipquarx »

Whoops, sorry had just woke up.

Edit:
You forgot the t in the last %string, Ipq.
« Last Edit: January 02, 2015, 02:15:13 PM by Thorfin25 »

ftfy

That for loop wont get %arg11. Gotta keep an eye out for these things.

That for loop wont get %arg11. Gotta keep an eye out for these things.
Wont it go up to 11, as 10 is less than 11?

That for loop wont get %arg11. Gotta keep an eye out for these things.
ey man i just noticed he was missing adding the args to the string and fixed it

Wont it go up to 11, as 10 is less than 11?

Yes, but the last argument is 11, not 10