Author Topic: Recursion/evaluating Strings Within Strings?  (Read 392 times)

So I recently released my Server Command Gui, which works great.  My goal for version 3 was to make every aspect of the gui recursive, meaning it can be repeated infinitely and can account for any number of commands.  As a part of this, I tried to change the way it constructed the command sent to the server.

This is the old way it sent the command:
Code: [Select]
eval("commandtoclient('"@getword($command),0)@"', strreplace(getword($command,1),%find, %replace), ... ");
With this method, I could support arguments that had more than one word, but I could only have as many arguments as I define in the script.

I tried to replace it with something kinda like this:
Code: [Select]
%find = "_";
%replace = " ";
%cmd = "commandtoserver("@addtaggedstring(getword($command, 0));
for(%a=1; %a<getwordcount($command); %a++)
%cmd = %cmd @ "," @ strreplace(getword($command, %a), %find, %replace);
%cmd = %cmd @ ");";
eval(%cmd);

This method worked for as many arguments as I could type into the text box, but when I tried to have an argument with more than one word, such as "messagesent hi_my_name_is_pedro" (note that "_" is replaced with " "), I would get a syntax error.

echoing %cmd would give me somthing like this:
Code: [Select]
commandtoserver(58, hi my name is pedro);

%cmd needs to look like this somehow
Code: [Select]
commandtoserver(58, "hi my name is pedro");But that would mean I need two different kinds of strings within another string, and that doesn't make alot of sense to me.


I tried to look for a solution to this, but all I came up with was a vague reference to parse string or something.

Is it possible to write this, so the eval(); is able to evaluate the strings within the strings while still retaining the ability to support infinite recursion?

%string = "\"" @ %string @ "\"";

%string = "\"" @ %string @ "\"";

I keep seeing stuff like that when I export my arrays, but I never knew what it was for.
are the double ""s mistakes or is that part of adding the backslashes?

It's like if you said "I am a douch" and you wanted to put another quote in it, except you'd put "I am a douch, \"Steve\" as we might call you."

AKA yes. \" makes the " not get counted as part of code, but as string.

It's like if you said "I am a douch" and you wanted to put another quote in it, except you'd put "I am a douch, \"Steve\" as we might call you."

AKA yes. \" makes the " not get counted as part of code, but as string.

Ok, thanks a bunch!

Also, does "\'"@$command@"\'" work as well?