Until is not working for loop Topic is solved

Ask gaming related questions
PassTheMayo
Posts: 3
Joined: 20 Mar 2017, 15:57

Until is not working for loop

20 Mar 2017, 16:02

So I am making an auto-AFK script for Minecraft. The script currently just does the following:

Code: [Select all] [Download] GeSHi © Codebox Plus

Hold W
Wait 1 second
Release W
Wait 1 second
Hold A
Wait 1 second
...

I want it to continue doing that until the keybind has been pressed again, but it stays in the loop even if I press the bind a second time. Here's my code:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Any help, please?
A_AhkUser
Posts: 536
Joined: 06 Mar 2017, 16:18
Location: France

Re: Until is not working for loop

20 Mar 2017, 16:54

Code: [Select all] [Download] GeSHi © Codebox Plus

#MaxThreadsPerHotkey 2 ; This setting is used to control how many "instances" of a given hotkey or hotstring subroutine are allowed to exist simultaneously


and here 2 is usefull since we want stop the subroutine using the same hotkey

expression which alongside untilis evaluated after the inner loop is reached see: https://autohotkey.com/docs/commands/Until.htm
so you have to check at each send, whith this aim in view you better off simplificate you multiline send by an expression with a loop

Code: [Select all] [Download] GeSHi © Codebox Plus

Loop, 4
MsgBox % ["w", "a", "s", "d"][a_index]


is the same as:



and since with have a loop in aloop with have to call break, 2 because if an inner loop is enclosed by an outer loop, the inner loop takes precedence
(see: https://autohotkey.com/docs/commands/Loop.htm)

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Video Game Reader
Image
github
demo
PassTheMayo
Posts: 3
Joined: 20 Mar 2017, 15:57

Re: Until is not working for loop

20 Mar 2017, 17:31

@A_AhkUser I've used your code and it did this on me:

http://prntscr.com/emg1i9
User avatar
Masonjar13
Posts: 1110
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: Until is not working for loop  Topic is solved

20 Mar 2017, 17:36

They simply forgot to update the loop count. Just as well, there is one too many s's in that array.

Code: [Select all] [Download] GeSHi © Codebox Plus

Loop 8
Send % "{" . ["w", "w", "a", "a", "s", "s", "d", "d"][a_index] . A_Space . (mod(a_index, 2) ? "up" : "down") . "}"

Edit: instead of embedded loops, why not use SetTimer?

Code: [Select all] [Download] GeSHi © Codebox Plus

^l::setTimer,MCBot,% (t:=!t)?1000:"off"

MCBot:
i:=1
loop 8
send % "{" . ["w", "a", "s", "d"][mod(a_index,2)?i:i++] . A_Space . (mod(a_index, 2) ? "up" : "down") . "}"
return
PassTheMayo
Posts: 3
Joined: 20 Mar 2017, 15:57

Re: Until is not working for loop

20 Mar 2017, 17:41

Masonjar13 wrote:They simply forgot to update the loop count. Just as well, there is one too many s's in that array.

Code: [Select all] [Download] GeSHi © Codebox Plus

Loop 8
Send % "{" . ["w", "w", "a", "a", "s", "s", "d", "d"][a_index] . A_Space . (mod(a_index, 2) ? "up" : "down") . "}"

Thank you, it worked!
A_AhkUser
Posts: 536
Joined: 06 Mar 2017, 16:18
Location: France

Re: Until is not working for loop

20 Mar 2017, 17:56

Masonjar13 wrote:They simply forgot to update the loop count. Just as well, there is one too many s's in that array.


sssorry... :oops:


Masonjar13 wrote:instead of embedded loops, why not use SetTimer?
niice solution
and never thinked about [a_index>4?a_index]thanks for sharing the tips ;)
Video Game Reader
Image
github
demo
User avatar
Masonjar13
Posts: 1110
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: Until is not working for loop

20 Mar 2017, 18:48

That was wildly incorrect, actually.. I've edited my code, which is now working. You could very well stick with having the full array still (with all the letters doubled); the difference between that and my fixed method are negligible at best, really.
A_AhkUser
Posts: 536
Joined: 06 Mar 2017, 16:18
Location: France

Re: Until is not working for loop

21 Mar 2017, 09:47



How couldn't see it!!

Masonjar13 wrote:That was wildly incorrect


for sure!

that's we call argument from authority: I saw Masonjar13, Россия, 828 posts so I said into myself :
русский программист it's an other level, святая речь it's true! It cannot be a badly written code!
Video Game Reader
Image
github
demo

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 10 guests