Ok so first up by RealTimeParsing i mean executing code from a variable, atm i have a very simple code just as a proof of concept that reads an entire script from a text file and then executes said script.
Now keep in mind this version is very inefficient and is nowhere near complete (the commands i added i chose specifically because they have visual components that you can see)
I could most likely cut out some of the If statements by using yet more functions but this is very much a WiP so im not too worried about optimization atm.
Now is this code useful? It could be in the future who knows, but for now its just a fun little project for me.
Code:
Begin
File.Show browse for file dialog("script")
File.Count number of lines("{script}", "lines")
Variable.Subtract (Math)("lines", "2")
Variable.Evaluate (Math)("{lines} - 1", "RunLoop")
File.Read first line("{script}", "loops")
if Variable.Is equal to("loops", "Infinite")
begin
File.Read line("{script}", "2", "Command")
Function.Execute("Run")
If Variable.Is greater than (Math)("lines", "1")
Begin loop("{RunLoop}")
File.Read next line("{script}", "Command")
Function.Execute("Run")
end
end
if Macro.Previous criteria was not met()
begin
File.Read line("{script}", "2", "Command")
Function.Execute("Run")
If Variable.Is greater than (Math)("lines", "1")
Begin loop("{RunLoop}")
File.Read next line("{script}", "Command")
Function.Execute("Run")
end
end
end
function("Run")
begin
if Variable.Is match (Regex)("Command", "Window.")
begin
if Variable.Is match (Regex)("Command", "Window.Display html dialog")
begin
Function.Execute setting 1 variable("arguments", "ArgCount", "5")
Variable.Get from collection("args", "1", "title")
Variable.Get from collection("args", "2", "X")
Variable.Get from collection("args", "3", "Y")
Variable.Get from collection("args", "4", "top")
Variable.Get from collection("args", "5", "message")
Variable.Clear collection("args")
Window.Display html dialog("{title}", "{X}", "{Y}", "{top}", "{message}")
end
if Variable.Is match (Regex)("Command", "Window.")
begin
if Variable.Is match (Regex)("Command", "Window.Display message box")
begin
Function.Execute setting 1 variable("arguments", "ArgCount", "2")
Variable.Get from collection("args", "1", "message")
Variable.Get from collection("args", "2", "wait")
Variable.Clear collection("args")
Window.Display message box("{message}","{wait}")
end
end
if Variable.Is match (Regex)("Command", "Window.Bring to front")
begin
Function.Execute setting 1 variable("arguments", "ArgCount", "5")
Variable.Get from collection("args", "1", "name")
Variable.Get from collection("args", "2", "exact")
Variable.Clear collection("args")
Window.Bring to front("{name}", "{exact}")
end
end
if Macro.Previous criteria was not met()
begin
if Variable.Is match (Regex)("Command", "Macro.")
begin
if Variable.Is match (Regex)("Command", "Macro.Pause")
begin
Function.Execute setting 1 variable("arguments", "ArgCount", "1")
Variable.Get from collection("args", "1", "Duration")
Variable.Clear collection("args")
Macro.Pause("{Duration}")
end
end
end
if Macro.Previous criteria was not met()
begin
if Variable.Is match (Regex)("Command", "Variable.")
begin
if Variable.Is match (Regex)("Command", "Variable.Set")
begin
Function.Execute setting 1 variable("arguments", "ArgCount", "2")
Variable.Get from collection("args", "1", "name")
Variable.Get from collection("args", "2", "value")
Variable.Clear collection("args")
Variable.Set("{name}", "{value}")
end
end
end
Variable.Set("Command", "0")
end
function
function("arguments")
begin
begin loop("{ArgCount}")
Variable.Increment (Math)("ArgNo")
Variable.Get match (Regex)("Command", ""([^"])*"", "{ArgNo}", "0", "argTemp")
Variable.Trim("argTemp", """)
Variable.Add to collection("args", "{argTemp}")
Variable.Remove("argTemp")
end
Variable.Set("ArgNo", "0")
end
function
Now onto dynamic variables.
A Dynamic variable being for instance {name{index}}, What i expected was that if i say put that in a command like.
Code:
Variable.Set ("index", "1")
Variable.Set ("{name{index}}", "blah")
That the variable name1 would point to the value blah.
Instead what happened was that variable.set would look for a variable named name{index} this of course was a problem at the time.
Now i tried and failed many times to to work around this.
This is one of my early examples that failed. It could create a nested variable fine, but it cant read it unless i hard code in the name of it (so here itd be var1) which defeats the purpose of this code
Code:
begin
Variable.Set("name", "var")
Variable.Set("index", "1")
Variable.Set("{name}{index}", "failure")
Variable.Evaluate (Text)("name{index}", "name2")
Variable.Set("{name2}", "Success")
Variable.Evaluate (Text)("{var1}", "test2")
Window.Display message box("{test2}", "yes")
end
So i came up with a solution using collections.
Code:
begin
Function.Execute setting 2 variables("write", "name", "test", "value", "success")
Function.Execute setting 3 variables("read", "name", "test", "index", "1", "variable", "var")
Window.Display message box("{variable}", "yes")
end
function("write")
begin
Variable.Add to collection("{name}", "{value}")
end
function
function("read")
begin
Variable.Get from collection("{name}", "{index}", "{variable}")
end
function
This not only fixed the reading issue but also cut the number of lines down to two lines not including the functions.
one for reading
one for writing
Now the code snippets im about to use as examples are out of date but you can find the full code
here (the snippets are from the second revision which is the second wall of text in that thread)
Code:
if Keyboard.Keys has been pressed within (ms)("{<tab>}", "150")
Begin
Variable.Increment (Math)("num")
Memory.Get value("_Launcher", "{PointerlocationX}", "float", "BaseX{num}")
Memory.Get value("_Launcher", "{PointerlocationY}", "float", "BaseY{num}")
Variable.Round (Math)("BaseX{num}", "0")
Variable.Round (Math)("BaseY{num}", "0")
Variable.Evaluate("Location number {num} has been set", "speech")
Speech.Say("{speech}", "yes")
End
This snippet would set the location so i need to use the write line twice
i would do this like so
Code:
if Keyboard.Keys has been pressed within (ms)("{<tab>}", "150")
Begin
Variable.Increment (Math)("num")
Memory.Get value("_Launcher", "{PointerlocationX}", "float", "BaseX")
Memory.Get value("_Launcher", "{PointerlocationY}", "float", "BaseY")
Variable.Round (Math)("BaseX", "0")
Variable.Round (Math)("BaseY", "0")
Function.Execute setting 2 variables("write", "name", "RandX", "value", "{baseX}")
Function.Execute setting 2 variables("write", "name", "RandY", "value", "{baseY}")
Variable.Evaluate("Location number {num} has been set", "speech")
Speech.Say("{speech}", "yes")
End
This would set index 1 of the collection named RandX to the value of BaseX the variable and the same with RandY and BaseY
If i executed the same code a second time it would input the same variables into index slot 2, so on and so on.
The next snippet is the code that would have read said variables.
Code:
Macro.Read stopwatch("area timer", "timer")
If Variable.Is greater than("timer", "max timer")
Begin
Variable.Set random number("num", "1", "{max}")
Variable.Set("BaseX", "BaseX{num}")
Variable.Set("BaseY", "BaseY{num}")
Variable.Set("Changing location", "1")
End
To modify this section to the new coding format i would do as such.
Code:
Macro.Read stopwatch("area timer", "timer")
If Variable.Is greater than("timer", "max timer")
Begin
Variable.Set random number("num", "1", "{max}")
Function.Execute setting 3 variables("read", "name", "RandY", "index", "{num}", "variable", "BaseX")
Function.Execute setting 3 variables("read", "name", "RandY", "index", "{num}", "variable", "BaseY")
Variable.Set("Changing location", "1")
End