Rendier Posted December 22, 2008 Posted December 22, 2008 (edited) Hey, I have an issue with an undeclared variable within a function. The main idea is that I DECLARE the variable BEFORE the function starts, and at the END of the FUNCTION, it gets altered. The reason why I want to do this, is to create a sequence of actions (Looping), that in the FIRST time it goes through the loop, it does something this way (with a case structure), and the second and next times it goes through it, it does something else. All said and done, I keep getting an error that I did not declare the variable used in the function, even tough I did. I tried making it a Global, I tried changing the function name tough: Func BjoraToFarm($Runs), and all kinds of crazy stuff. Anyways, here is the code, I hope someone can help me out on this one: (It's probably a stupid mistake, but I've only just started scripting in AutoIt, so I could be concidered, well, a noob:)) expandcollapse popupWinactivate("Program") ;This is the game I want it to work for; Winwaitactive("Program") Sleep (2000) Call("BjoraToFarm") ;Calling the first function here; Global $Runs=0 [color="#9ACD32"];Delcaring my variable;[/color]Func BjoraToFarm() [color="#00FF00"];What he does in game, is run from one spot, to another;[/color] Select Case $Runs=0 Call("Run1") Case $Runs>=1 Call("Run1") EndSelect EndFunc Func Run1() Send ("{numpad0}") $rndnumber = random(200, 300) Sleep ($rndnumber) Send ("{space}") $rndnumber = random(1000, 1100) Sleep ($rndnumber) Send ("{numpad4}") $rndnumber = random(10000, 11000) Sleep ($rndnumber) $Runs = $Runs + 1 Call ("funcX") EndFunc Func Run2() Send ("{numpad0}") $rndnumber = random(200, 300) Sleep ($rndnumber) Send ("x") $rndnumber = random(200, 300) Sleep ($rndnumber) Send ("{space}") $rndnumber = random(1000, 1100) Sleep ($rndnumber) Send ("{numpad4}") $rndnumber = random(10000, 11000) Sleep ($rndnumber) $Runs = $Runs + 1 Call ("funcX") EndFunc So the main idea is that when I initially launch the program, it starts with a $run = 0, and thus goes to the Run1 loop. It then continues the script (I left that part out for obvious reason, keeping it short), and once it's done, it goes BACK to the INITIAL LOCATION and starts over. $Runs SHOULD BE higher than 0 now, and thus he should ALWAYS follow Run2 from there one. (No matter how much loops he does, he should ALWAYS select Run2) In my eyes, this should work. AutoIt obviously disagrees, and thus I'm posting here for help:) EDIT: Unbelievable, the milisecond I click the post button, and read through the post (for spelling errors), I find the mistake in my code. I CALL the function BEFORE declaring the variable, thus it skips that. In other words, to fix my problem, all I needed to was place the Global BEFORE I called the function. I feel stupid right now... *Apologies* Thanks in advance, Rendier Edited December 22, 2008 by Rendier
Bowmore Posted December 22, 2008 Posted December 22, 2008 Don't beat yourself up too much. I think most of us will have made that mistake at some time. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
bo8ster Posted December 22, 2008 Posted December 22, 2008 I've done that so many times, now I read my post before I hit the post button And it is ALWAYS something small. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now