Blue Eye Logo

Blue Eye Macro

Automation is freedom
It is currently Sun Oct 22, 2017 6:58 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Dragons projects - Dynamic Variables and RealTimeParsing
Thanked: 0 time(s)  Unread post Posted: Fri Sep 04, 2015 7:26 pm 
Lifetime VIP Contributor
Lifetime VIP Contributor
User avatar



Joined: Mon Sep 26, 2011 9:38 am
Posts: 1702
Location: Space Australia
Been thanked: 78 time(s)
Has thanked: 6 time(s)
Contribution Points: 9991
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

_________________
ImageImageImageImage
Image


Last edited by Thedragonfiend on Fri Sep 04, 2015 7:28 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Dragons Projects - Dynamic Variables and RealTimeParsing
Thanked: 0 time(s)  Unread post Posted: Fri Sep 04, 2015 7:27 pm 
Lifetime VIP Contributor
Lifetime VIP Contributor
User avatar



Joined: Mon Sep 26, 2011 9:38 am
Posts: 1702
Location: Space Australia
Been thanked: 78 time(s)
Has thanked: 6 time(s)
Contribution Points: 9991
-Reserved for future projects-

_________________
ImageImageImageImage
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Dragons projects - Dynamic Variables and RealTimeParsing
Thanked: 0 time(s)  Unread post Posted: Wed Jul 13, 2016 9:32 am 
New User
New User



Joined: Wed Jul 13, 2016 8:49 am
Posts: 2
Been thanked: 0 time(s)
Has thanked: 0 time(s)
Contribution Points: 13
This is beyond my knowledge so that I have enough.

_________________
บาคาร่าบนมือถือ


Top
 Profile  
Reply with quote  
 Post subject: Re: Dragons projects - Dynamic Variables and RealTimeParsing
Thanked: 0 time(s)  Unread post Posted: Sun Aug 06, 2017 10:23 pm 
Lifetime VIP Contributor
Lifetime VIP Contributor
User avatar



Joined: Mon Sep 26, 2011 9:38 am
Posts: 1702
Location: Space Australia
Been thanked: 78 time(s)
Has thanked: 6 time(s)
Contribution Points: 9991
Made a few tweaks to the parser (still havnt added new commands but these tweaks enable a project im currently working on for a new game bot)

Specifically this section of the code, I added a file cache flush because I noticed it wasnt updating the cache when i reread a file when I got curious and edited the script mid runtime, i also changed the none infinite loop to an actual loop, as I forgot to do that when I originally wrote the code snippet and it wasnt apparent to me as i never actually tested the loop setting (herp derp)

Code:
 Begin
     File.Show browse for file dialog("script")
     // Variable.Set("script", "C:\Users\teatime\Documents\test.txt") Artifact from my testing just ignore this line
     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 loop("{loops}")
               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
     File.Flush cache()
 end


As for why it enables me to run a new game botting project? well check out this bad boy, its a very simple mock-up, just creates a file on the c drive with these contents
Code:
1
Window.Display message box('Hello','yes')


Nothing fancy, until you get to the file cache flush, at which point it completely deletes the script it created at the start and rewrites it to tell you that it just flushed the cache.

If you delete the script file on the c drive while its running it will detect that its deleted, recreate it but this time the message will ask why you tried to delete it.

Now why is this important? simple, its rewriting itself on the fly, based on variable outcomes it is completely rewriting the script that it is executing, now the implementation below is just a rough cut example and has no real logic behavior to it so its hard to see how this would help me with a game bot.

I plan to use this method to code a pathfinding script for a game, specifically a game that has randomized map layouts with specific tilesets, i plan to use this code to have the bot learn the tilesets and slowly build up a database where it basically says "if this landmark exists at X coordinate then load X tileset path" or to say "I get stuck at this location so i will path around it"

Basically... Every time the script runs it should get slightly more efficient as every time it runs into an error that i programmed it to detect it will try something different, if that something different also creates an error it will try again, effectively the script will run a genetic algorithm.

Code:
 Begin
     Variable.Set("runcounter", "0")
     Variable.Set("script", "C:\LearningAiTest.txt")
     File.Write text("{script}", "no", "1")
     File.Write text("{script}", "yes", "Window.Display message box('hello', 'yes')")
     Begin loop("-1")
          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 loop("{loops}")
                    File.Read line("{script}", "2", "Command")
                    if  File.Does not exist("{script}")
                         begin
                              File.Write text("{script}", "no", "1")
                              // Function.Execute setting 1 variable("Rewrite", "linecount", "")
                              File.Write text("{script}", "yes", "Window.Display message box('Why did you try to delete me?','yes'")
                         end
                    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  Variable.Is greater than (Math)("runcounter", "4")
               begin
                    File.Write text("{script}", "no", "1")
                    File.Write text("{script}", "yes", "Window.Display message box('Why are you still here?','yes')")
               end
          if  Macro.Previous criteria was not met()
               begin
                    File.Write text("{script}", "no", "1")
                    File.Write text("{script}", "yes", "Window.Display message box('I just flushed the cache for you, you are welcome','yes'")
                    Variable.Increment (Math)("runcounter")
               end
          File.Flush cache()
     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.Get match (Regex)("Command", "'([^'])*'", "{ArgNo}", "0", "argTemp")
               Variable.Trim("argTemp", """)
               Variable.Trim("argTemp", "'")
               Variable.Add to collection("args", "{argTemp}")
               Variable.Remove("argTemp")
          end
          Variable.Set("ArgNo", "0")
     end
function
 

_________________
ImageImageImageImage
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


You cannot post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group