A simple issue Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
BlooDoesntPlay
Posts: 17
Joined: 26 Nov 2021, 07:39

A simple issue

Post by BlooDoesntPlay » 27 Nov 2021, 00:54

Hello again, I've come back with another probably simple issue. I know my last post was a spelling mistake, I'm about 99% sure that's not the issue this time. My problem, is that I can't get this function to read FunctionSelection from inside, it just shows FunctionSelection as nothing. I have another keybind set up to change function selection from 0 to 1 and back, but it doesn't matter because every time I call DC, it treats FunctionSelection as if it's nothing, which doesn't make sense because other keybinds read it just fine. I'm posting the entire code just so, if something else is messing with it, someone can point it out. The problem is the DC function, which is short for double click because I got a million calls for clicking and I was tired of typing it out.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

^0::
	NewList := Object(0,"a",1,"b",2,"c")
	x := 0
	y := 0
	MouseGetPos, x, y
	ToolTip Mouse Position is %x% and %y%
	;ToolTip %clipboard%
	clipboard := x " " y
	;TempVar := NewList.MaxIndex()
	;ToolTip %TempVar%
	Sleep 2000
	ToolTip

return


FunctionSelection := 0

DC(clicks, x, y, sleeptime)

;Where clicks are the times to click, x and y are coordinates, sleep time is the delay between clicks, and in place, an optional parameter, is if we are clicking where the mouse is or the set coordinates
{
	ToolTip Is %FunctionSelection%
	if FunctionSelection = 1
	;Bypass for if you start it accidentally, you can swap off
	{
		
	}
	else
	{
		temp := 0
		while temp < clicks
		{
			temp += 1
			MouseClick, Left, x, y
			
			Sleep sleeptime
		}
	}
}
^p::
	FunctionSelection += 1
	
	if (FunctionSelection >= 2) 
		FunctionSelection := 0
	
	if FunctionSelection = 0
	{
		ToolTip Function 0 active
		Sleep 1000
		ToolTip
	}
	if FunctionSelection = 1
	{
		ToolTip Function 1 active
		Sleep 1000
		ToolTip
	}
	
	;ToolTip Number %FunctionSelection%
return

^o::
	DC(1,100,100,50)
return
The issue being, if you hit Control + P, and it says Function 1 active, hitting Control + O shouldn't do anything, but it still does. What gives?

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

Re: A simple issue  Topic is solved

Post by boiler » 27 Nov 2021, 04:26

You have a variable scope issue. For the DC function to be able to see the FunctionSelection variable, it would have to declare it as global.

Also, your line that initializes the value of FunctionSelection to 0 never gets executed because it is unreachable code. See the documentation regarding the auto-execute section.

BlooDoesntPlay
Posts: 17
Joined: 26 Nov 2021, 07:39

Re: A simple issue

Post by BlooDoesntPlay » 27 Nov 2021, 05:28

Thank you, putting variables to be used by specific functions right before the functions is a habit I picked up from Lua, I'll have to remember not to do that for this. Also, thank you for linking to global's, it didn't catch my attention because I could reference variables in the hotkey stuff, but not in the function. I didn't realize they would have to be declared global if it was in the very beginning, I figured anything underneath would be able to reference it.

Post Reply

Return to “Ask for Help (v1)”