Page 1 of 1

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

Posted: 30 Apr 2024, 09:42
by florenceee01
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

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

Posted: 30 Apr 2024, 09:48
by boiler
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.

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

Posted: 30 Apr 2024, 11:06
by florenceee01
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

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

Posted: 30 Apr 2024, 12:48
by boiler
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.

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

Posted: 30 Apr 2024, 22:27
by florenceee01
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}

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

Posted: 30 Apr 2024, 22:52
by florenceee01
sorry for all misunderstanding
i achieve what i needed on this viewtopic.php?p=88115#p88115
my approach is actually wrong, my bad.

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

Posted: 06 May 2024, 10:58
by Scr1pter
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!