Jump to content

Variable changing help - (Moved)


prot0555
 Share

Go to solution Solved by Musashi,

Recommended Posts

  • Solution
2 hours ago, prot0555 said:

I cannot change the value of a variable with the script. it gives me error:Statement cannot just be a expression. plz help

I have no clue what you want to achieve with this "script".  A detailed description would be helpful.
As you can notice yourself from the compiler messages, there are various syntax errors.

For example, MouseGetPos is a function, so you have to set parentheses () even if you don't pass any values. Otherwise, it is treated as a variable that is currently neither declared nor has a value assignment.

Here is a (quick & dirty) example, but it likely won't do what you want.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_OutFile_Type=a3x
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

HotKeySet("{ESC}", "_Terminate") ; *** just in case of endless loop

Local $4ever = 1, $ff = 1
Local $aNum ; Array

Run("notepad.exe")
If @error Then Exit MsgBox(BitOr(4096, 16), "Error : ", "Run Notepad fails -> Exit")

Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)
WinActivate($hWnd)

Do
    ; Info : Dimension Values for MouseGetPos
    ; None returns a two-element array containing the mouse coordinates :
    ;   $aArray[0] = X coord (horizontal), $aArray[1] = Y coord (vertical)

    If ProcessExists("notepad.exe") Then $aNum = MouseGetPos()
    ClipPut(" X=" & $aNum[0] & "  Y=" & $aNum[1] & @CRLF)
    ControlSend($hWnd, "", "Edit1", ClipGet(), 1) ; 1 = $SEND_RAW
    Sleep(500)

    $4ever += 1
    Sleep(500)
Until $4ever = 6
 _Terminate()

; -------------------------------------------
Func _Terminate()
    WinClose($hWnd)

    ; answer "Quit Notepad dialog" :
    WinWaitActive("[CLASS:#32770]")
    Sleep(500)
    Send("{TAB}{ENTER}")

    Exit;
EndFunc   ;==>_Terminate

 

EDIT :

Local $a = 1
Local $b = 2

; 1. Do not enclose $a, to which you want to assign a value, in parentheses.
; ($a) = $b   ; <=== Error
; Use :
$a = $b
ConsoleWrite($a & @CRLF)
$a = ($b)
ConsoleWrite($a & @CRLF)
$a = ($b) + 10
ConsoleWrite($a & @CRLF)

; 2. Calculations on the left side of the assignment also result in an error.
; $a + 10 = $b     ; <=== Error
; ($a + 10) = $b   ; <=== Error

; 3. It is different when using e.g. conditional statements :
$a = 5
$b = $a + 5
If ($a + 10) > $b Then
    ConsoleWrite(($a + 10) & " is greater than " & $b & @CRLF)
Else
    ConsoleWrite(($a + 10) & " is not greater than " & $b & @CRLF)
EndIf

 

P.S. Next time please post the source code (see the code tag < > in the header of the message window.) and not a screenshot.

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

@Musashiis correct here when he says:

; 1. Do not enclose $a, to which you want to assign a value, in parentheses.
; ($a) = $b   ; <=== Error

The parens indicate to the interpreter an expression, even if you are just enclosing a single variable.

As far as the interpreter is concerned, you might as well be saying:

($a * 1) = $b

which doesn’t make a lot of sense.

Code hard, but don’t hard code...

Link to comment
Share on other sites

22 hours ago, Musashi said:

I have no clue what you want to achieve with this "script".  A detailed description would be helpful.
As you can notice yourself from the compiler messages, there are various syntax errors.

For example, MouseGetPos is a function, so you have to set parentheses () even if you don't pass any values. Otherwise, it is treated as a variable that is currently neither declared nor has a value assignment.

Here is a (quick & dirty) example, but it likely won't do what you want.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_OutFile_Type=a3x
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

HotKeySet("{ESC}", "_Terminate") ; *** just in case of endless loop

Local $4ever = 1, $ff = 1
Local $aNum ; Array

Run("notepad.exe")
If @error Then Exit MsgBox(BitOr(4096, 16), "Error : ", "Run Notepad fails -> Exit")

Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)
WinActivate($hWnd)

Do
    ; Info : Dimension Values for MouseGetPos
    ; None returns a two-element array containing the mouse coordinates :
    ;   $aArray[0] = X coord (horizontal), $aArray[1] = Y coord (vertical)

    If ProcessExists("notepad.exe") Then $aNum = MouseGetPos()
    ClipPut(" X=" & $aNum[0] & "  Y=" & $aNum[1] & @CRLF)
    ControlSend($hWnd, "", "Edit1", ClipGet(), 1) ; 1 = $SEND_RAW
    Sleep(500)

    $4ever += 1
    Sleep(500)
Until $4ever = 6
 _Terminate()

; -------------------------------------------
Func _Terminate()
    WinClose($hWnd)

    ; answer "Quit Notepad dialog" :
    WinWaitActive("[CLASS:#32770]")
    Sleep(500)
    Send("{TAB}{ENTER}")

    Exit;
EndFunc   ;==>_Terminate

 

EDIT :

Local $a = 1
Local $b = 2

; 1. Do not enclose $a, to which you want to assign a value, in parentheses.
; ($a) = $b   ; <=== Error
; Use :
$a = $b
ConsoleWrite($a & @CRLF)
$a = ($b)
ConsoleWrite($a & @CRLF)
$a = ($b) + 10
ConsoleWrite($a & @CRLF)

; 2. Calculations on the left side of the assignment also result in an error.
; $a + 10 = $b     ; <=== Error
; ($a + 10) = $b   ; <=== Error

; 3. It is different when using e.g. conditional statements :
$a = 5
$b = $a + 5
If ($a + 10) > $b Then
    ConsoleWrite(($a + 10) & " is greater than " & $b & @CRLF)
Else
    ConsoleWrite(($a + 10) & " is not greater than " & $b & @CRLF)
EndIf

 

P.S. Next time please post the source code (see the code tag < > in the header of the message window.) and not a screenshot.

Thanks this was what I wanted!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...