how to run 2 loop consecutively after the first loop is done

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
florenceee01
Posts: 4
Joined: 30 Apr 2024, 09:28

how to run 2 loop consecutively after the first loop is done

30 Apr 2024, 09:42

I'm trying to run this, but my if statement is not executing to press f7 so the f7 is not starting to loop

thanks

Code: Select all

$F6::
MyVar := 0
Loop 3
{
MouseClick, left

MyVar++

if (%MyVar% = 3) {
   Send {F7}
}
}
Return

$F7::
Loop 3
{
MouseClick, right
}
Return
User avatar
boiler
Posts: 17173
Joined: 21 Dec 2014, 02:44

Re: how to run 2 loop consecutively after the first loop is done

30 Apr 2024, 09:48

You don't put % symbols around an expression for normal purposes, which yours is in your if statement, which is the version of if for expressions.

Run this demonstration to see the difference:

Code: Select all

MyVar := 3
if (%MyVar% = 3)
	MsgBox, It works with percent symbols
else
	MsgBox, It doesn't work with percent symbols
if (MyVar = 3)
	MsgBox, It works without percent symbols
else
	MsgBox, It doesn't work with percent symbols

Yes, it can be confusing, but you can avoid all the confusion between legacy/command syntax and expressions by using AHK v2, which uses expressions throughout.
florenceee01
Posts: 4
Joined: 30 Apr 2024, 09:28

Re: how to run 2 loop consecutively after the first loop is done

30 Apr 2024, 11:06

thanks boiler

I tried it on with if (MyVar = 3)
it still not pressing f7

i also tried

Code: Select all

if (MyVar = 3)
	Send {F7}
else
	Send {F7}
still not pressing f7
anyway i'll try it on v2
User avatar
boiler
Posts: 17173
Joined: 21 Dec 2014, 02:44

Re: how to run 2 loop consecutively after the first loop is done

30 Apr 2024, 12:48

florenceee01 wrote: I tried it on with if (MyVar = 3)
it still not pressing f7
What are you expecting to happen when it sends F7?

This shows that the script itself (when corrected as I suggested) works, by beeping a low-pitch 3 times followed by high-pitch beep only the third time:

Code: Select all

F6::
MyVar := 0
Loop 3
{
	SoundBeep, 500
	MyVar++

	if (MyVar = 3)
	   SoundBeep, 1000
}
return

florenceee01 wrote: anyway i'll try it on v2
The fact that it's v1 isn't the problem and won't be fixed by translating it to v2. How are you checking to see if F7 is sent? Replace that line with a MsgBox and I'm sure you'll see the MsgBox pop up.
florenceee01
Posts: 4
Joined: 30 Apr 2024, 09:28

Re: how to run 2 loop consecutively after the first loop is done

30 Apr 2024, 22:27

boiler wrote:
30 Apr 2024, 12:48
florenceee01 wrote: I tried it on with if (MyVar = 3)
it still not pressing f7
What are you expecting to happen when it sends F7?

This shows that the script itself (when corrected as I suggested) works, by beeping a low-pitch 3 times followed by high-pitch beep only the third time:

Code: Select all

F6::
MyVar := 0
Loop 3
{
	SoundBeep, 500
	MyVar++

	if (MyVar = 3)
	   SoundBeep, 1000
}
return

florenceee01 wrote: anyway i'll try it on v2
The fact that it's v1 isn't the problem and won't be fixed by translating it to v2. How are you checking to see if F7 is sent? Replace that line with a MsgBox and I'm sure you'll see the MsgBox pop up.

it works on msgbox but when i tried this code, which should press f7 to run a loop inside f7 doesn't work.

Code: Select all

if (MyVar = 3)
	Send {F7}
else
	Send {F7}
florenceee01
Posts: 4
Joined: 30 Apr 2024, 09:28

Re: how to run 2 loop consecutively after the first loop is done

30 Apr 2024, 22:52

sorry for all misunderstanding
i achieve what i needed on this viewtopic.php?p=88115#p88115
my approach is actually wrong, my bad.
User avatar
Scr1pter
Posts: 1277
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: how to run 2 loop consecutively after the first loop is done

06 May 2024, 10:58

Hi,

I think the main problem is $F7::

The $ prevents your other script (F6) from executing the F7 script.
Instead, it just sends a regular F7 key press rather than running the script.

Cheers!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: arrondark and 93 guests