Jump to content

Changing Numeric Value Of Variable


Deltoan
 Share

Recommended Posts

Hello,

I have been studying the AutoIt Help files and am currently trying to assign a value to a variable. I'll post the script that I'm using below this message. Basically, I want $Stage to equal 0 at the start and after going through "If $Stage = 0 Then", $Stage's value will change to 1. After If = 1 it changes to 2 and after If = 2 it changes back to 0 to cycle through the If statements again. The issue that I'm having with my current commands is that the value of $Stage does not change from 0. I know this is very basic but its late and I'm not having much luck with it. Thanks in advance for any help.

P.S. Sorry for the lack of layout of the text, Its tabbed/spaced properly before submitting the post. I marked the spots that I am questioning proper syntax by making them red.

Dim $Stage

;;;;Sets variable for If Statements

HotKeySet("o", "Stage")

;;;;Script is triggered when "o" is pressed.

While 1

Sleep (100)

WEnd

;;;;Required

Func Stage ()

If $Stage = 0 Then

$Stage = 1

Send("{numpad4}")

Sleep(250)

MouseClick("left")

Sleep(500)

;;;;If the variable = 0 then the above is executed and the variable's value changes to 1

ElseIf $Stage=1 Then

$Stage = 2

Send("{numpad4}")

Sleep(250)

MouseClick("left")

Sleep(500)

;;;;If the variable = 1 then the above is executed and the variable's value changes to 2

ElseIf $Stage=2 Then

$Stage = 0

Send("{numpad4}")

Sleep(250)

MouseClick("left")

Sleep(500)

;;;;If the variable = 2 then the above is executed and the variable's value changes to 0

EndIf

EndFunc

:::::::::::::::::::::::::::::::::::::::::::::::::

Edited by Deltoan
Link to comment
Share on other sites

This?

Global $Stage = 0 ;<-this
;;;;Sets variable for If Statements

HotKeySet("o", "Stage")
;;;;Script is triggered when "o" is pressed.

;blah blah blah

I tried using Global and had the same issue. From what I understand, if I don't assign a value to the variable by using "Dim $Stage" or "Global $Stage" then by default, the value of $Stage is 0. Or are you saying that I need to use "Global $Stage = 1" to change the starting value of 0 to 1 in the first IF Statement? Edited by Deltoan
Link to comment
Share on other sites

Dim $Stage = 0

That's all that is needed for the script to run. Don't assume if you declare a variable it will be 0 automatically ;)

I thought the same at first but the line "If $Stage = 0 then" executes every single time I press "o". Even if I don't declare the variable. Just to be sure, I tried declaring it to 0 at the start and sure enough its still only executing the If = 0 line. It should execute If = 1 the 2nd time and If = 2 the third. The fourth would be If = 0 again cause If = 2 sets it back to 0.

Link to comment
Share on other sites

DID you actually TRY your script with our modification???

I guess you didn't because you're "babbling" now.

see for yourself:

Dim $Stage = 0
;;;;Sets variable for If Statements

HotKeySet("o", "Stage")
;;;;Script is triggered when "o" is pressed.

While 1
Sleep (100)
WEnd
;;;;Required

Func Stage ()
If $Stage = 0 Then
MsgBox(0, "0", $Stage)
$Stage = 1

;Send("{numpad4}")
;Sleep(250)
;MouseClick("left")
Sleep(500)
;;;;If the variable = 0 then the above is executed and the variable's value changes to 1

ElseIf $Stage=1 Then
MsgBox(0, "1", $Stage)
$Stage = 2
;Send("{numpad4}")
;Sleep(250)
;MouseClick("left")
Sleep(500)
;;;;If the variable = 1 then the above is executed and the variable's value changes to 2

ElseIf $Stage=2 Then
MsgBox(0, "2", $Stage)
$Stage = 0
;Send("{numpad4}")
;Sleep(250)
;MouseClick("left")
Sleep(500)
;;;;If the variable = 2 then the above is executed and the variable's value changes to 0

EndIf
EndFunc

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

DID you actually TRY your script with our modification???

I guess you didn't because you're "babbling" now.

see for yourself:

Dim $Stage = 0
;;;;Sets variable for If Statements

HotKeySet("o", "Stage")
;;;;Script is triggered when "o" is pressed.

While 1
Sleep (100)
WEnd
;;;;Required

Func Stage ()
If $Stage = 0 Then
MsgBox(0, "0", $Stage)
$Stage = 1

;Send("{numpad4}")
;Sleep(250)
;MouseClick("left")
Sleep(500)
;;;;If the variable = 0 then the above is executed and the variable's value changes to 1

ElseIf $Stage=1 Then
MsgBox(0, "1", $Stage)
$Stage = 2
;Send("{numpad4}")
;Sleep(250)
;MouseClick("left")
Sleep(500)
;;;;If the variable = 1 then the above is executed and the variable's value changes to 2

ElseIf $Stage=2 Then
MsgBox(0, "2", $Stage)
$Stage = 0
;Send("{numpad4}")
;Sleep(250)
;MouseClick("left")
Sleep(500)
;;;;If the variable = 2 then the above is executed and the variable's value changes to 0

EndIf
EndFunc

Yes I did test it, notice that the OP indicates that I'm new to AutoIt. Stupidity would be an assumption on your end. It turns out that the script was working correctly the whole time but due to my error of having the exact same key-press for each execution, I was not able to notice it working properly. Its all good now. Thank you for the help!

P.S. I didn't think to use a message box for testing it. Great idea!

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...