Deltoan 0 Posted September 2, 2010 (edited) 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 StatementsHotKeySet("o", "Stage");;;;Script is triggered when "o" is pressed.While 1 Sleep (100)WEnd;;;;RequiredFunc 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 EndIfEndFunc::::::::::::::::::::::::::::::::::::::::::::::::: Edited September 2, 2010 by Deltoan Share this post Link to post Share on other sites
omikron48 0 Posted September 2, 2010 (edited) This? Global $Stage = 0 ;<-this ;;;;Sets variable for If Statements HotKeySet("o", "Stage") ;;;;Script is triggered when "o" is pressed. ;blah blah blah Edited September 2, 2010 by omikron48 Share this post Link to post Share on other sites
enaiman 16 Posted September 2, 2010 (edited) Dim $Stage = 0That's all that is needed for the script to run. Don't assume if you declare a variable it will be 0 automatically Edited September 2, 2010 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example scriptwannabe "Unbeatable" Tic-Tac-ToePaper-Scissor-Rock ... try to beat it anyway :) Share this post Link to post Share on other sites
Deltoan 0 Posted September 2, 2010 (edited) 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 September 2, 2010 by Deltoan Share this post Link to post Share on other sites
Deltoan 0 Posted September 2, 2010 Dim $Stage = 0That'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. Share this post Link to post Share on other sites
enaiman 16 Posted September 2, 2010 DID you actually TRY your script with our modification??? I guess you didn't because you're "babbling" now. see for yourself: expandcollapse popupDim $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 scriptwannabe "Unbeatable" Tic-Tac-ToePaper-Scissor-Rock ... try to beat it anyway :) Share this post Link to post Share on other sites
Deltoan 0 Posted September 2, 2010 Oh wow, I just noticed that the same commands are for each IF statement. I'll adjust that to the right keys presses and test it again. I really shouldn't be doing this at 1 am Share this post Link to post Share on other sites
Deltoan 0 Posted September 2, 2010 DID you actually TRY your script with our modification??? I guess you didn't because you're "babbling" now. see for yourself: expandcollapse popupDim $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! Share this post Link to post Share on other sites