Jump to content
Sign in to follow this  
GeekIT

Creating a simple script-engine with autoit.

Recommended Posts

GeekIT

Hello readers of this post  :)

I'm planning to make a sort of script engine via autoit.

It will read text files as 'scripts' with my self made scripting language.

(but i'm going to make my own extension for the 'scripts')

i'm thinking about " nameOfFile.GeekScript " or something...

how it works:

files with the extension ".geekscript" will be opened with my "script-engine.exe" made in autoit.

-script-engine.exe reads the script and breaks it apart in sentences by @CRLF.

-every sentence will be spitted up to 'words' (or commands) that will be recognized by my script-engine.

-the engine recognizes if you want to make a variable when it reads a word followed by '=' and after that a string or number (or calculations).

and here i'm stuck, if the script engine reads this for example:

-----------------------------------------------------------------------------

ABC = 456

DEF = "this is a test" & ABC + 123

-----------------------------------------------------------------------------

for the variable "DEF", it must calculate the result for that variable and store that in a dictionary object or something.
i tough of using autoit's "execute" or "eval" function to see what the output would be but unfortunately if by coincidence the
variable exists in the 'script-engine source code' eval or execute will use that variable...
 

this is what i mean:

-----------------------------------------------------------------------------

Func = 456

-----------------------------------------------------------------------------

if i use eval or execute for this string: eval("func = 456") then it would give an error or it won't work.

same for variables that exist in the 'script-engine autoit code'...

does anybody know if there is a way for calculating strings like eval does, but don't use the variables made in the autoit script?

 

Share this post


Link to post
Share on other sites
jdelaney

Requires you to have the 'Func' declared, unfortunatly:

Local $Func
$string = "Func = 456"
$aString = StringRegExp($string,"(.*)\s=\s(.*)",3)
$VarName = $aString[0]
$VarValue = $aString[1]
Assign($VarName,$VarValue)
ConsoleWrite("VariableName=[" & $VarName & "], Value=[" & Eval($VarName) & "] or, using your 'variable'=[" & $Func & "]" & @CRLF )

output: VariableName=[Func], Value=[456] or, using your 'variable'=[456]

edit: no need to move the array into $VarName...helpfile states the first param of assign can't be an array, but am able to do so...must mean it can't be an empty array element?:

Local $Func
$string = "Func = 456"
$aString = StringRegExp($string,"(.*)\s=\s(.*)",3)
Assign($aString[0],$aString[1])
ConsoleWrite("using your 'variable'=[" & $Func & "]" & @CRLF )

output: using your 'variable'=[456]

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
GeekIT

Requires you to have the 'Func' declared, unfortunatly:

Local $Func
$string = "Func = 456"
$aString = StringRegExp($string,"(.*)\s=\s(.*)",3)
$VarName = $aString[0]
$VarValue = $aString[1]
Assign($VarName,$VarValue)
ConsoleWrite("VariableName=[" & $VarName & "], Value=[" & Eval($VarName) & "] or, using your 'variable'=[" & $Func & "]" & @CRLF )

output: VariableName=[Func], Value=[456] or, using your 'variable'=[456]

edit: no need to move the array into $VarName...helpfile states the first param of assign can't be an array, but am able to do so...must mean it can't be an empty array element?:

Local $Func
$string = "Func = 456"
$aString = StringRegExp($string,"(.*)\s=\s(.*)",3)
Assign($aString[0],$aString[1])
ConsoleWrite("using your 'variable'=[" & $Func & "]" & @CRLF )

output: using your 'variable'=[456]

 

thank you for the reply!

i see you are using stringregexp, can you explain me what you are doing with that?

also, wouldn't it be more useful to store the name in a dictionary object or has stringregexp something to do with that?

to "calculate" the string i was thinking about first replacing all the possible declared variables in my "geek script" with there outputs

but the problem then is that a variable can be declared in a very complicated way:

myVar = 1 + -5 * 8 / 7 - 5 & "test" + -1 - -10 & "help!!!"

Share this post


Link to post
Share on other sites
BuckMaster

I am trying to do something very similar in one of my scripts,

I like how jdelaney went about it but for what I am doing I cannot declare the variables before.

I came up with this real quick and it works for what you are trying to do,

there are a couple ways you could improve it because right now it will confuse similar variable names ex. ABC and ABCD

I can think of a couple ways of fixing this but i think you can figure it out ;)

#include <Array.au3>

Dim $TestScript = 'ABC = 456' & @CRLF & _
                  'DEF = "this is a test" & ABC + 123' & @CRLF & _
                  'myVar =  1 + -5 * 8 / 7 - 5  & "test" &  -1 - -10  & "help!!!"' & @CRLF & _
                  'Func = 456' & @CRLF

ProcessScript($TestScript)

Func ProcessScript($hScript)
    Local $hSplit = StringSplit($hScript, @CRLF, 1)
    Local $Variables[1] = [0], $Data[1] = [0]
    For $i = 1 to $hSplit[0] Step 1
        Local $aString
        $aString = StringRegExp($hSplit[$i],"(.*)\s=\s(.*)",3)
        If IsArray($aString) Then
            _ArrayAdd($Variables, $aString[0])
            _ArrayAdd($Data, $aString[1])
            $Variables[0] += 1
            $Data[0] += 1
        EndIf
    Next
    For $i = 1 to $Variables[0] Step 1
        ConsoleWrite("+ Variable["&$i&"] = "&$Variables[$i]&@CRLF)
        ConsoleWrite("> Data["&$i&"]     = "&$Data[$i]&@CRLF)
    Next
    For $i = 1 to $Data[0] Step 1
        Local $ProcessData = $Data[$i]
        For $c = 1 to $Variables[0] Step 1
            If StringinStr($Data[$i], $Variables[$c]) Then
                $ProcessData = StringReplace($Data[$i], $Variables[$c], $Data[$c])
            EndIf
        Next
        ConsoleWrite("- Processed Data["&$i&"]     = "&Execute($ProcessData)&@CRLF)
    Next
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • lenclstr746
      By lenclstr746
      Hi guys,
      Some functions of my script are running slowly. Very slow. What is the reason?
      My Code:
      <snip>
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • nacerbaaziz
      By nacerbaaziz
      Hello all
      I found this function in the Internet
      It is to play audio files from  the compiled script
      I did not understand just one thing on this function
      func play($name, $wait = 0) local Const $SND_RESOURCE = 0x00040004 local Const $SND_ASYNC = 1 ; Play the file - the script will pause as it sounds if $wait = 0 then DllCall("winmm.dll", "int", "PlaySound", "str", $name, "hwnd", 0, "int", BitOR($SND_RESOURCE, $SND_ASYNC)) else DllCall("winmm.dll", "int", "PlaySound", "str", $name, "hwnd", 0, "int", $SND_RESOURCE) endIf return 1 endFunc What I did not understand was this variable
      local Const $SND_RESOURCE = 0x00040004 I know that this variable is contains the resource name
      But what if I want to change the name of the resource what i'll do?
      can i do that?
      Thanks in advance
       
    • krasnoshtan
      By krasnoshtan
      Hello forum users!
      At some point I had a need to restart my script. Is it possible to do this with autoit or do I need to connect additional scripts like .cmd or .bat?
      For example: i have only script.au3 and it's running. Wich code shoud i use to exit from the script and start it again?
    • tintin92
      By tintin92
      Hello,

      How can I automatically download a list of zip files, like the ones in the quote, using a AutoIt script?
      Is it possible with AutoIt script?
       
×