Author Topic: commandToServer With A Variable  (Read 1173 times)

How would I use commandToServer with %command? I tried commandToServer(%command); (crashed Blockland) and commandToServer('%command'); (didn't work).

Huh. I guess I could just use eval.

commandtoserver(addtaggedstring(%command), %args);

commandtoserver(addtaggedstring(%command), %args);
Thanks. Useful information. But I'm still using eval, so I don't need to do %arg1, %arg1, %arg2, %arg3, %arg4, %arg5, and so forth.

Thanks. Useful information. But I'm still using eval, so I don't need to do %arg1, %arg1, %arg2, %arg3, %arg4, %arg5, and so forth.
Why would you use eval for something like this?

Why would you use eval for something like this?
Converting this
clientCmdUpdateActionMenu("UI Text#someServerCmd, arg1, arg2, arg3|UI Text#anotherServerCmd, arg1, arg2, arg3|UI Text#someOtherServerCmd, arg1, arg2, arg3");
Into a GUI bitmap button controls and doing command = "eval(\"commandToServer(\'" @ %command @ "\'," @ %args @ ");\");"; (I do a bunch of separating and filtering and stuff before this).

Converting this
clientCmdUpdateActionMenu("UI Text#someServerCmd, arg1, arg2, arg3|UI Text#anotherServerCmd, arg1, arg2, arg3|UI Text#someOtherServerCmd, arg1, arg2, arg3");
Into a GUI bitmap button controls and doing command = "eval(\"commandToServer(\'" @ %command @ "\'," @ %args @ ");\");"; (I do a bunch of separating and filtering and stuff before this).
But with the command field of a gui control you're creating a string that is going to be evaluated, so you could just do this:
command = "commandtoserver(\'" @ %command @ "\'," @ %args @ ");";
There's no need for a double eval.

But with the command field of a gui control you're creating a string that is going to be evaluated, so you could just do this:
command = "commandtoserver(\'" @ %command @ "\'," @ %args @ ");";
There's no need for a double eval.
Good idea/point.

Unashamed self promotion: http://forum.returntoblockland.com/dlm/viewFile.php?id=3499

relevant bit:

Code: [Select]
%find = "_";
%replace = " ";
%cmd = "\'"@ getword($servercommandgui::command_[%key,%x], 0) @"\'";
for(%a=1; %a<getwordcount($servercommandgui::command_[%key,%x]); %a++)
%cmd = %cmd @ ",\"" @ strreplace(getword($servercommandgui::command_[%key,%x], %a), %find, %replace) @ "\"";
eval("commandtoserver("@%cmd@");");

Where $servercommandgui::command_[%key, %x] will be a string like "messagesent potato" or "slay rykuta"
The first word is the command and each word after is an argument.