Sign in to follow this  
Followers 0
GeekIT

Creating a simple script-engine with autoit.

4 posts in this topic

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



#2 ·  Posted (edited)

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

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

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  
Followers 0

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.
      Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.
      I'll attach a portion of the code in order to let you understand what my script does.
      $objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer If @error Then ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else For $objElement In $objIE_h1 $strInnerText = $objElement.innerText Next Select Case StringInStr($strInnerText, "QUESTION") ; Here is the question ; PS4 PRO $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here For $objElement In $objSpans If $i >= 4 Then $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3 If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i $j = $i - 4 $objInput = _IEGetObjById($objIE, "answer_" & $j) If @error Then ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF) Else _IEAction($objInput, "click") If @error Then ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error) Else ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF) ExitLoop EndIf EndIf EndIf $i+=1 Else $i+=1 EndIf Next $i = 0 $j = 0 This is what my script does.
      Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).
      How can I make all of these, faster?
      If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!
      Thanks for your help
    • au3leecher
      By au3leecher
      Hellow everybody,
      I tryed to manipulate a game called "Assault Cube" which is a easy beginning in coding. I run the code but the wished value doesn't change, i don't understand why.
      The Pointers are fine, I checked that the pointers don't change every time while restart the game.
      My Code:
      <snip>
      _____________________________________________________________________________________________________________________________________________________________________________________________
      Checklist:
      The Offsets are 18C & 4
      In Cheat Engine: ("ac_client.exe"+0010F418) <- Pointer
      4 Bytes = 'dword'
       
    • nacerbaaziz
      By nacerbaaziz
      Hello
      How are you
      I have a question, please.
      I've created a window and i need
      when i run the script if it detect an other copy from the same script was runing
       the script close the first copy Automatically and run a new copy
      I want an example to understand it
    • Nareshm
      By Nareshm
      Please Somebody Help me i am trying to create new script but, i don't know how to create it.

      I am Creating script like this :
      ; My script here [First Script]
      Check the internet connection, if internet connected then
      ; My Script here [Second Script]
      If internet not connected, wait for connect, after connected run my second script
      If Control id/windows/title matched do nothing and end/exit autoit script
      If Control id/windows/title not matched repeat my first and second script again until control id/windows/tittle not matched

      match with :
      >>>> Window <<<<
      Title:    PS :: Version - 2.8.0.0  - [PS Bill]
      Class:    WindowsForm734a
      Position:    -8, -8
      Size:    1382, 744
      Style:    0x17CD0000
      ExStyle:    0x00050100
      Handle:    0x0000000000130572
      >>>> Control <<<<
      Class:    WindowsForm734a
      Instance:    15
      ClassnameNN:    WindowsForm34a15
      Name:    BillPrint
      Advanced (Class):    [NAME:BillPrint]
      ID:    7875
      Text:    
      Position:    39, 310
      Size:    1221, 306
      ControlClick Coords:    745, 20
      Style:    0x56010000
      ExStyle:    0x00000000
      Handle:    0x00000000000C0468
       
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I am a totally blind young man
      for easier to read books and articles Among the blind
      i has programmed a tool
      This tool converts text to audio with the possibility to save it into a wav or mp3 file
      It is also compatible with all persons, whether blind or ordinary
      I have completed the work of this tool and want to take your opinion
      i Especially published here for anyone looking about how to convert text to speech, I will put this tool open source for you
      I want to know what your think about it
      and if it need any other additions?
      Note :
      This tool converts texts to audio using sapi 5 voices
      so i was also puted a hot keys to control the tool
      Now I put this project to you for public benefit and I am ready to answer any question.
      Apology :
      I am an Arab youth from Algeria
      I do not mastered English very well
      So I apologize to you if there are written mistakes
      With my greetings and best wishes
      My texts to audio converter.zip