Putting multiple actions in a single script Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Malfatto
Posts: 3
Joined: 29 Sep 2022, 21:11

Putting multiple actions in a single script

Post by Malfatto » 29 Sep 2022, 21:20

Hello
I found this code on the internet and adapted it for my needs. I know very little of AutoHotkey. I duplicated it in the same script but when I click Run Script it says error in line 48 a function with that name already exists and won't work. It points to Actions. Here are the two I'm trying to put together:

Code: Select all

#IfWinActive ahk_exe ReadyOrNot-Win64-Shipping.exe
Shift & Q::
 {
   count++
   settimer, actions, 350
 }
return

actions:
 {
   if (count = 1)
    {
      Send {MButton}
      Sleep 50
      Send {2}
      Sleep 50
      Send {2}.
    }
   else if (count = 2)
    {
      Send {MButton}
      Sleep 50
      Send {3}
      Sleep 20
      Send {3}
      Sleep 50
      Send {2}.
    }
      count := 0
 }
return
And the other is:

Code: Select all

#IfWinActive ahk_exe ReadyOrNot-Win64-Shipping.exe
Shift & E::
 {
   count++
   settimer, actions, 350
 }
return

actions:
 {
   if (count = 1)
    {
      Send {MButton}
      Sleep 50
      Send {2}
      Sleep 50
      Send {1}.
    }
   else if (count = 2)
    {
      Send {MButton}
      Sleep 50
      Send {3}
      Sleep 50
      Send {3}
      Sleep 50
      Send {1}.
    }
      count := 0
 }
return
How do I put these two together in the same file? I searched for Action but found nothing.
Thank you.

User avatar
boiler
Posts: 16771
Joined: 21 Dec 2014, 02:44

Re: Putting multiple actions in a single script

Post by boiler » 29 Sep 2022, 21:38

As the error message suggests, don’t put the Action subroutine in the same script twice.

Malfatto
Posts: 3
Joined: 29 Sep 2022, 21:11

Re: Putting multiple actions in a single script

Post by Malfatto » 30 Sep 2022, 06:46

But without the Actions it doesn't work. What should I do?

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Putting multiple actions in a single script

Post by jNizM » 30 Sep 2022, 06:52

Rename the Actions to (e.g) ActionQ and ActionE. Or change it to a function and give it parameter(s) if just one of the send is different to the other.
Also you dont need 2x same #IfWinActive. Just write both between #IfWinActive and return
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

Rohwedder
Posts: 7553
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Putting multiple actions in a single script  Topic is solved

Post by Rohwedder » 30 Sep 2022, 07:08

Hallo,
my suggestion:

Code: Select all

#IfWinActive ahk_exe ReadyOrNot-Win64-Shipping.exe
+q:: ;Shift & Q
Qcount++
settimer, Qactions, -350
return
Qactions:
Switch Qcount
{
Case 1:
	Send {MButton}
	Sleep 50
	Send {2}
	Sleep 50
	Send {2}.
Case 2:
	Send {MButton}
	Sleep 50
	Send {3}
	Sleep 20
	Send {3}
	Sleep 50
	Send {2}.
}
Qcount := 0
return
+e:: ;Shift & E
Ecount++
settimer, Eactions, -350
return
Eactions:
Switch Ecount
{
Case 1:
	Send {MButton}
	Sleep 50
	Send {2}
	Sleep 50
	Send {1}.
Case 2:
	Send {MButton}
	Sleep 50
	Send {3}
	Sleep 50
	Send {3}
	Sleep 50
	Send {1}.
}
Ecount := 0
return

Malfatto
Posts: 3
Joined: 29 Sep 2022, 21:11

Re: Putting multiple actions in a single script

Post by Malfatto » 30 Sep 2022, 08:00

Thank you very much. Both answers were very helpful, but I can choose only one.

Post Reply

Return to “Gaming Help (v1)”