| Blockland Forums > Modification Help |
| Recursion/evaluating Strings Within Strings? |
| (1/2) > >> |
| Nexus:
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: ---eval("commandtoclient('"@getword($command),0)@"', strreplace(getword($command,1),%find, %replace), ... "); --- End code --- 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: ---%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); --- End code --- 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: ---commandtoserver(58, hi my name is pedro); --- End code --- %cmd needs to look like this somehow --- Code: ---commandtoserver(58, "hi my name is pedro"); --- End code --- 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? |
| MegaScientifical:
%string = "\"" @ %string @ "\""; |
| Nexus:
--- Quote from: MegaScientifical on June 07, 2011, 06:50:34 PM ---%string = "\"" @ %string @ "\""; --- End quote --- 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? |
| MegaScientifical:
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. |
| Nexus:
--- Quote from: MegaScientifical on June 07, 2011, 06:55:55 PM ---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. --- End quote --- Ok, thanks a bunch! |
| Navigation |
| Message Index |
| Next page |