Jason786 Posted June 11, 2010 Share Posted June 11, 2010 Global $Active = 0 While 1 If $Active = 1 Then Hey, so I know global declares a variable, I found this tutorial script on the internet so $Active must be the variable right So how does the script get from $Active = 0 to $Active = 1 , what does the 1 mean in this case? Also does it have to be While 1 or can it be just While? Thanks Link to comment Share on other sites More sharing options...
AlmarM Posted June 11, 2010 Share Posted June 11, 2010 The $Active variable isn't changed in your script. It will stay 0 forever. Until you change it using (for example) $Active = 1.The While loop keeps repeating itself as a statement is true. In this case While 1, 1 will always be true, so the loop wont stop until you exit the script or use an ExitLoop.Example 1HotKeySet("{HOME}", "SetActive") ; Press 'home' to set $Active to 1 Global $Active = 0 While 1 If $Active = 1 Then ConsoleWrite("Something is now active." & @CRLF) EndIf If $Active = 0 Then ConsoleWrite("Something isn't active." & @CRLF) EndIf Sleep(1000) WEnd Func SetActive() $Active = 1 EndFuncExample 2HotKeySet("{HOME}", "StopLoop") ; Press 'home' to stop the loop. Global $Statement = 1 While $Statement = 1 ConsoleWrite("While loop is active." & @CRLF) Sleep(1000) WEnd ConsoleWrite("While loop stopped." & @CRLF) Func StopLoop() $Statement = 0 EndFuncDoes this help you?AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
rudi Posted June 11, 2010 Share Posted June 11, 2010 Hi. Global $Active = 0 While 1 If $Active = 1 Then ; ... Hey, so I know global declares a variable, I found this tutorial script on the internet so $Active must be the variable right So how does the script get from $Active = 0 to $Active = 1 , what does the 1 mean in this case? Also does it have to be While 1 or can it be just While? Thanks You could have read the autoit help file, topic "while". While <condition> ... WEnd is looping again and again, as long as "<condition>" is true. Here <condition> is "1", so the loop will loop for ever. Usually a statement like "If $Active = <something> then ExitLoop" will break out of this infinite looping. that's all Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Jason786 Posted June 11, 2010 Author Share Posted June 11, 2010 (edited) Thanks So if I do If $Active = 1 Then $SquarePosition = PixelSearch(0, 0, 1696, 1036, 0x941616, 3) When does Active turn to 1? Because if Active is 1 right, so how does it change to 1? Hope you guys understand what I'm asking :S edit: oh I see, so you gotta make active = something. thanks HotKeySet("{a}", "_Start") Func _Start() $Active = 1 EndFunc ;==>_Start Some like that would be right then? Edited June 11, 2010 by Jason786 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 11, 2010 Moderators Share Posted June 11, 2010 (edited) Jason786,Please take this advice in the friendly sense I am giving it! It is obvious that you have very little idea about coding and program structure. Nothing wrong with that, we all started there! Could I suggest that before going any further, you read the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) - this will help you enormously. You should also look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page). There are even video tutorials on YouTube if you prefer watching to reading. In the particular case you mention above, $Active will only turn to 1 (or 0 or any other value) when your script tells it to - like here: ; Set our variable $Active = 1 ; Set a counter to zero $iCount = 0 ; Start a loop which continues until $Active is no longer 1 While $Active = 1 ; Increase the count $iCount += 1 ; Check if the count has reached a certaib value. if it has then set $Active to 0 If $iCount = 10 Then $Active = 0 ; Keep going round the loop if $Active = 1 WEnd ; To get here, $Active must = 0 - and we changed it when $iCount = 10 ; So let us see if we are right MsgBox(0, "End", "$iCount = " & $iCount)I hope you can follow what is happening in the script and that it answers your question.I really do recommend those tutorials - getting a good base knowledge of coding will serve you well in future. M23Edit: Your edit shows you are on the right lines already! Edited June 11, 2010 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
niubbone Posted June 11, 2010 Share Posted June 11, 2010 Since i'm pretty new to it i can perfectly understand what you are asking.Global $Active = 0While 1 If $Active = 1 ThenAs said, $active will stay 0 forever. Now I'll explain your piece of code line by line very clearly.Global $Active = 0We state that the Global variable $Active is 0.While 1We set an infinite loop. This will keep running infinitely the code below, since there isn't a condition that makes it exit. That is because 1 its like True boolean operator, so it's like While True.If $Active = 1 ThenThis is where you got stuck. We just check continuosly IF THE VARIABLE $Active IS EQUAL TO 1, we DON'T STATE that is equal to 1. That $Active is a condition of the If statement.To make a more humanlike example:You want to exit from house, but door it's locked with a key.Global $Active = Door it's lockedWhile 1; I keep continuosly pulling the handle to see if door is open If $Active = Door isn't locked anymore Then; the door it's open and i can go out. Exit and go out with friendsAs you can see, the door won't magically unlock by itself. It needs you to pick the key and open it. So if you put it like thisGlobal $Active = 0 Door it's locked$Active = 1; I pick the key and open the doorWhile 1; Keeping pulling the handle to see if door is open If $Active = 1 Then If door it's open Exit and go out with friendsThat's it. Sounds ridiculous, i know, but i think it gave the idea Link to comment Share on other sites More sharing options...
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