Data_Unavailable Posted January 28 Share Posted January 28 Normally use python but need autoit for a specific project, I'm trying to run a for loop which is controlled by a variable which is taken from an inputbox, something like this in python but in autoit, python text below, can't find online or figure out how to do this without using a while loop: amount = int(input("How many times would you like this to run? ")) for i in range(amount): Link to comment Share on other sites More sharing options...
Developers Jos Posted January 28 Developers Share Posted January 28 Helpfile might give you all the answers you want when it comes to syntax... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
TimRude Posted January 28 Share Posted January 28 https://www.autoitscript.com/autoit3/docs/functions/InputBox.htm https://www.autoitscript.com/autoit3/docs/keywords/For.htm Link to comment Share on other sites More sharing options...
Data_Unavailable Posted January 28 Author Share Posted January 28 1 hour ago, Jos said: Helpfile might give you all the answers you want when it comes to syntax... #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> Func Inputter() $Amount = Number(InputBox("Test box", "How many times shall I run?", "0", "", -1, -1, 0, 0)) EndFunc Func Opera() MouseMove(722,407) MouseClick($MOUSE_CLICK_LEFT) Sleep(100) MouseMove(704,403) MouseClick($MOUSE_CLICK_LEFT) Sleep(100) MouseMove(1181,281) MouseClick($MOUSE_CLICK_LEFT) MouseMove(838,525) MouseClick($MOUSE_CLICK_LEFT) Sleep(1000) MouseMove(22,52) MouseClick($MOUSE_CLICK_LEFT) EndFunc Call(Inputter()) ;Local $Timeout = 10 ;MsgBox($MB_SYSTEMMODAL,"ETC","This will timeout in 10 seconds.",10) MouseMove(571,836) MouseClick($MOUSE_CLICK_LEFT) For $Amount = 1 To $Amount Step 1 Call(Opera()) Next Kind've fixed it, works now but doesn't repeat with this but repeats under other conditions, still working on it. Link to comment Share on other sites More sharing options...
Data_Unavailable Posted January 28 Author Share Posted January 28 Doesnt work, dont understand why, spent more than 5 hours trying to get this working, i need help. Decided to not use a For loop as that didnt work either, ive narrowed the problem down to the input, the $sAmount variable just doesnt work, but any other variable does work at the bottom when needs to be equal to $count. #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> Func Inputter() Local $sAmount = (InputBox("Test box", "How many times shall I run?", "0", "", -1, -1, 0, 0)) $sAmount=Number($sAmount) EndFunc Func Opera() MouseMove(722,407) MouseClick($MOUSE_CLICK_LEFT) Sleep(100) MouseMove(704,403) MouseClick($MOUSE_CLICK_LEFT) Sleep(100) MouseMove(1181,281) MouseClick($MOUSE_CLICK_LEFT) MouseMove(838,525) MouseClick($MOUSE_CLICK_LEFT) Sleep(1000) MouseMove(22,52) MouseClick($MOUSE_CLICK_LEFT) EndFunc ;Local $count=0 Call(Inputter()) ;Local $Timeout = 10 ;MsgBox($MB_SYSTEMMODAL,"ETC","This will timeout in 10 seconds.",10) MouseMove(571,836) MouseClick($MOUSE_CLICK_LEFT) ;For $i = 1 To $Amount Step 1 ; Call(Opera()) ;Next Do Call(Opera()) $count = $count+1 Until $count>$sAmount Link to comment Share on other sites More sharing options...
Nine Posted January 28 Share Posted January 28 Could you tell what application you are trying to automate ? Does not make much sense the way you are doing it (sorry to say). “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to comment Share on other sites More sharing options...
genius257 Posted January 28 Share Posted January 28 (edited) Hi @Data_Unavailable Here is your working code: #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> Global $sAmount Func Inputter() $sAmount = (InputBox("Test box", "How many times shall I run?", "0", "", -1, -1, 0, 0)) $sAmount = Number($sAmount) EndFunc Func Opera() MouseMove(722,407) MouseClick($MOUSE_CLICK_LEFT) Sleep(100) MouseMove(704,403) MouseClick($MOUSE_CLICK_LEFT) Sleep(100) MouseMove(1181,281) MouseClick($MOUSE_CLICK_LEFT) MouseMove(838,525) MouseClick($MOUSE_CLICK_LEFT) Sleep(1000) MouseMove(22,52) MouseClick($MOUSE_CLICK_LEFT) EndFunc Global $count=0 Inputter() ;Local $Timeout = 10 ;MsgBox($MB_SYSTEMMODAL,"ETC","This will timeout in 10 seconds.",10) MouseMove(571,836) MouseClick($MOUSE_CLICK_LEFT) ;For $i = 1 To $Amount Step 1 ; Call(Opera()) ;Next Do Opera() $count = $count+1 Until $count>=$sAmount Here comes the explanation to the changes: You defined $sAmount as a Local variable within the Inputter function. Doing so it is available within the function only, so i instead added it as a global variable and referenced it in the function. In you latest post, you commented out your variable definition of $count, so using it in the loop below resulted in a crash. Also using Local outside a function works, but does basically the same as global, except confuse the reader. You used the Call function for function calls. This is not how the Call function works. Your expression within the Call function parentheses was executed the actual call, and the Call function afterwards tried to execute the response as a function, failing silently via the @error flag. And finally i changed your greater than condition to a greater or equal to, as the loop +1 of the requested number given from the input box. But all in all, i think this is a great start for you . You seem to take (constructive) criticism well and the script was 90% working already, nice Hope it helps! Edited January 28 by genius257 My Scripts: AutoIt Package Manager, AutoItObject Pure AutoIt, Corsair CUE SDK Github: AutoIt HTTP Server, AutoIt HTML Parser Link to comment Share on other sites More sharing options...
Data_Unavailable Posted January 29 Author Share Posted January 29 Currently I'm a student and my homework system is google classrooms, I have a few dozen pieces of homework outstanding from last year from when i had covid, and i could manually go into and mark them as submitted, and i thought i could make this code do that easily as an auto clicker, but i tripped out yesterday trying to make the loop, when I start a project I normally like to finish it. Basically the script moves the mouse from starting the program and clicks the google tab on taskbar, then goes into the homework, and then clicks the go back button in top left corner and loops to start of program after where it enters google. Link to comment Share on other sites More sharing options...
Data_Unavailable Posted January 29 Author Share Posted January 29 12 hours ago, genius257 said: Hi @Data_Unavailable Here is your working code: #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> Global $sAmount Func Inputter() $sAmount = (InputBox("Test box", "How many times shall I run?", "0", "", -1, -1, 0, 0)) $sAmount = Number($sAmount) EndFunc Func Opera() MouseMove(722,407) MouseClick($MOUSE_CLICK_LEFT) Sleep(100) MouseMove(704,403) MouseClick($MOUSE_CLICK_LEFT) Sleep(100) MouseMove(1181,281) MouseClick($MOUSE_CLICK_LEFT) MouseMove(838,525) MouseClick($MOUSE_CLICK_LEFT) Sleep(1000) MouseMove(22,52) MouseClick($MOUSE_CLICK_LEFT) EndFunc Global $count=0 Inputter() ;Local $Timeout = 10 ;MsgBox($MB_SYSTEMMODAL,"ETC","This will timeout in 10 seconds.",10) MouseMove(571,836) MouseClick($MOUSE_CLICK_LEFT) ;For $i = 1 To $Amount Step 1 ; Call(Opera()) ;Next Do Opera() $count = $count+1 Until $count>=$sAmount Here comes the explanation to the changes: You defined $sAmount as a Local variable within the Inputter function. Doing so it is available within the function only, so i instead added it as a global variable and referenced it in the function. In you latest post, you commented out your variable definition of $count, so using it in the loop below resulted in a crash. Also using Local outside a function works, but does basically the same as global, except confuse the reader. You used the Call function for function calls. This is not how the Call function works. Your expression within the Call function parentheses was executed the actual call, and the Call function afterwards tried to execute the response as a function, failing silently via the @error flag. And finally i changed your greater than condition to a greater or equal to, as the loop +1 of the requested number given from the input box. But all in all, i think this is a great start for you . You seem to take (constructive) criticism well and the script was 90% working already, nice Hope it helps! Ah thanks this helps a lot, I was thinking that local just meant that the variable was high priority or something 🤔. 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