Trying to use for loop to structure redundant data

Get help with using AutoHotkey and its commands and hotkeys
gravanoc
Posts: 13
Joined: 23 Sep 2018, 16:11

Trying to use for loop to structure redundant data

02 Jun 2020, 11:38

I'm a bit confused by the for loop syntax used in AHK, and maybe what I'm thinking of is not available, or I'm just unused to the syntax.

My goal is to assist in iterating over the same two alternating commands about 50 times.

Code: Select all

sleep, 25
Send i
Ideally, I could use some kind of loop to just repeat that behavior, without simply copying and pasting 50 times. Maybe the for ... in loop isn't geared towards this issue? Thank you.
swagfag
Posts: 3924
Joined: 11 Jan 2017, 17:59

Re: Trying to use for loop to structure redundant data

02 Jun 2020, 12:15

Code: Select all

Loop 50
{
	sleep, 25
	Send i
}
for is for looping through collections, like arrays, or calling enumerators
yoman_81
Posts: 3
Joined: 26 May 2020, 11:15

Re: Trying to use for loop to structure redundant data

02 Jun 2020, 18:48

so in the same way:

Code: Select all


random, diceroll, 1, 30
; we need this later
remainder := 30 - %diceroll%

; send tabs for the amount of diceroll result
Loop %diceroll% 
{
sleep 25
Send {Tab}
}
; send only ONCE after a random amount of tabs
Send {Space}
; now send the remaining tabs up to the amount of "max" 
Loop  %remainder%
 {
sleep 25
Send {Tab}
 } 
should work too?
what I wanted to do;
- roll between 1,30 , result is the var "diceroll"
- Run a command times the amount of the diceroll
- Run a different command, ONLY ONCE
- Run a command times %remainder%. %remainder% is "maximum roll minus diceroll result"

for later: the maximum for the roll needs to be derived from yet another parameter and not be static. (as in random, diceroll, 1, %MAXVAR%)

any obvious syntax errors?
User avatar
Chunjee
Posts: 608
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: Trying to use for loop to structure redundant data

02 Jun 2020, 19:34

You got some legacy syntax in there and questionable indentation.

I think this should help:

Code: Select all

random, diceroll, 1, 30
; we need this later
remainder := 30 - diceroll

; send tabs for the amount of diceroll result
Loop, % diceroll {
	sleep 25
	Send {Tab}
}
; send only ONCE after a random amount of tabs
Send {Space}
; now send the remaining tabs up to the amount of "max" 
Loop % remainder {
	sleep 25
	Send {Tab}
} 

Return to “Ask For Help”

Who is online

Users browsing this forum: anhnha, pnKed, SilasDeVis and 60 guests