Vanberk Posted May 30, 2009 Share Posted May 30, 2009 Hello everyone! I am new here and have already got myself into a problem Anyway... I used AC Tool before I came here, but now I want to make one of my macros in AutoIt. My problem is that I want to put in a variable in the call. for $i = 1 to 2 step 1 call ("level"&$i) next I have a function called level1 and another one called level2, so I want it to first call level1 and then level2. -Vanberk Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 30, 2009 Share Posted May 30, 2009 What is the problem then? The code you posted does exactly what you described you wanted it to do. See here: for $i = 1 to 2 step 1 call ("level"&$i) next Func level1() ConsoleWrite(1 & @CRLF) EndFunc Func level2() ConsoleWrite(2 & @CRLF) EndFunc .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Vanberk Posted May 30, 2009 Author Share Posted May 30, 2009 oh, hmm.. better i post the whole thing then?expandcollapse popup$speed = 200 Hotkeyset("{esc}", "Esc") Hotkeyset("^s", "start") while 1 sleep(500) wend func Esc() Exit 0 EndFunc Func start() WinWaitActive("xxxxxx") sleep(500) MouseMove(460, 455) MouseClick("left") sleep(500) for $i = 1 to 2 step 1 call ("level"&$i) next endfunc func wait() sleep(6000) endfunc Func left($loopX) for $loopX = 1 to $loopX send("{left}") sleep($speed) next EndFunc Func right($loopX) for $loopX = 1 to $loopX send("{right}") sleep($speed) next EndFunc Func up($loopX) for $loopX = 1 to $loopX send("{up}") sleep($speed) next EndFunc Func down($loopX) for $loopX = 1 to $loopX send("{down}") sleep($speed) next EndFunc Func level1() call ("right" & "1") call ("down" & "2") call ("right" & "2") call ("down" & "1") call ("right" & "1") call ("wait") EndFunc func level2() EndFuncHere is the AC Tool code:expandcollapse popupconstants speed = 200 // delay end SetActiveWindow xxxxxx delay 1000 MousePos 450, 489 leftclick delay 500 loop 11 call {loopno} end // settings procedure left using loopX loop $loopX keydown {left} 50 delay $speed end end Procedure right using loopX loop $loopX keydown {right} 50 delay $speed end end procedure up using loopX loop $loopX keydown {up} 50 delay $speed end end procedure down using loopX loop $loopX keydown {down} 50 delay $speed end end procedure wait delay 6000 end // levels procedure 1 // level 1 call right 1 call down 2 call right 2 call down 1 call right 1 call wait // level 1 Done end procedure 2 // level 2 call up 1 call right 1 call down 1 call right 3 call up 3 call right 1 call down 2 call right 4 call up 1 call left 1 call up 1 call wait // level 2 done end Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 30, 2009 Share Posted May 30, 2009 That is not how you use parameters, you aren't even supposed to have any Call() in there. Open the helpfile and check the page "Func...Return...EndFunc" .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Vanberk Posted May 30, 2009 Author Share Posted May 30, 2009 Wait? now I'm confused! Not supposed to have any call().. so I should just have: level1()? $speed = 200 for $i = 1 to 2 step 1 level&$i() next Func right($loopX) for $loopX = 1 to $loopX send("{right}") sleep($speed) next EndFunc Func down($loopX) for $loopX = 1 to $loopX send("{down}") sleep($speed) next EndFunc Func level1() right(1) down(2) EndFunc Func level2() right(3) down(1) EndFunc Oh... and my AC Tool macro is working 100% so, I just need the same thing but in AutoIt -Vanberk Link to comment Share on other sites More sharing options...
Vanberk Posted May 30, 2009 Author Share Posted May 30, 2009 Something is still wrong I think it have to be the: Func left($loopX) for $loopX = 1 to $loopX send("{left}") sleep($speed) next EndFunc Anyway this is the script I have right now: expandcollapse popup$speed = 500 Hotkeyset("{esc}", "Esc") Hotkeyset("^s", "start") while 1 sleep(500) wend func Esc() Exit 0 EndFunc Func start() WinWaitActive("xxxxxx") sleep(500) MouseMove(460, 455) MouseClick("left") sleep(500) level1() level2() endfunc func wait() sleep(6000) endfunc Func left($loopX) for $loopX = 1 to $loopX send("{left}") sleep($speed) next EndFunc Func right($loopX) for $loopX = 1 to $loopX send("{right}") sleep($speed) next EndFunc Func up($loopX) for $loopX = 1 to $loopX send("{up}") sleep($speed) next EndFunc Func down($loopX) for $loopX = 1 to $loopX send("{down}") sleep($speed) next EndFunc Func level1() right(1) down(2) right(2) down(1) right(1) wait() EndFunc func level2() up(1) right(1) down(1) right(3) up(3) right(1) down(2) right(4) up(1) left(1) up(1) wait() EndFunc -Vanberk Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 30, 2009 Share Posted May 30, 2009 Something is still wrong I think it have to be the: Func left($loopX) for $loopX = 1 to $loopX send("{left}") sleep($speed) next EndFuncHow do you expect that loop to work? Loop from 1 to 1.... If you only want the code to run 1 time then why do you even have a loop? Thanubis example is probably more like what you want. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
James Posted May 30, 2009 Share Posted May 30, 2009 Make sure $speed is a global variable. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Vanberk Posted May 30, 2009 Author Share Posted May 30, 2009 Yes, that is definitely causing a problem. Try this. Func left($loopX) for $X = 1 to $loopX send("{left}") sleep($speed) next EndFunc Ah.. that that was 1 of the problem The biggest problem was that I needed a Opt("SendKeyDownDelay", 50) <.< Even if i had the sleep It didnt get the send for some reason. Anyway thanks everyone for helping me! It works as it should now oh.. 1 last question >.< for $X = 1 to 33 level&$X() next I still want to know how to make it work like this... (I know that the code doesnt work) Im going to have 33 levels and there will else be alot of level1(), level2(), level3()...... -Vanberk Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 30, 2009 Share Posted May 30, 2009 (edited) Call("level" & $X) Edit: or Execute(), whatever.... Edited May 30, 2009 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Vanberk Posted May 31, 2009 Author Share Posted May 31, 2009 Here I am again!It's still a call problem so it is better to post it here than doing a whole new topic Who doesn't like the shorter codes?.. I made a new Func that is named Master that would do the job of the other 4.I also added a ini reader so I could put lots of stuff in a .ini file.Func Master($send, $loopX) for $X = 1 to $loopX send("" & $send & "") sleep($speed) next EndFunc Func level1() $var = IniReadSection("D:\Program\AutoIt3\Macros\level.ini", "Master") If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0][0] Call("Master", $var[$i][1]) next endif wait() EndFunclevel.ini[Master] Right={right} Down={down} Right={right} Down={down} Right={right}I believe that one or more of these 3 is the problem. I have tried to change them all, but still can't find a solution.Call("Master", $var[$i][1]) Func Master($send, $loopX) send("" & $send & "") Link to comment Share on other sites More sharing options...
oMBRa Posted May 31, 2009 Share Posted May 31, 2009 Func ''Master'' has 2 parameters but you are calling it passing only 1 parameter ( only $var[$i][1]) Link to comment Share on other sites More sharing options...
Vanberk Posted May 31, 2009 Author Share Posted May 31, 2009 Func ''Master'' has 2 parameters but you are calling it passing only 1 parameter ( only $var[$i][1])Damn right I am stupid... I can blame that I was tired? I haven't noticed that it had $loopX from the old Func, which I had before. And now it is worthless ... It works as it should now. thanks oMBRa -Vanberk 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