Help with a GUI script and an error I don't understand

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
IMTIREDSHUTUP
Posts: 5
Joined: 24 Apr 2019, 22:03

Help with a GUI script and an error I don't understand

24 Apr 2019, 22:29

Wassup, I'm here trying to make a code that when two specific pixels become two specific colors, it starts a countdown starting at 40 seconds that refreshes at intervals lower than 100 milliseconds. Yet, every time the middle part of the code runs it points to the line containing

Code: Select all

Gui, Add, Text, vD y0, %Start%
saying "Error: The same variable cannot be used for more than one control.
Specifically: vD y0
The current thread will exit."
The countdown still works, but the error pops up.
I want it to be that once the countdown timer finishes, the program won't exit, but instead go back to the beginning and restart the process.
I believe it is set up that way, but it doesn't want to execute the line specified above. I honestly copied most of this and don't really know much of it other than that it adds to the gui with each line. I don't understand the vD, but other than that I pretty much got the gist.

At this point, I don't really care too much if you explain it to me, I just want it to work.

Code: Select all

Beginning:
PixelGetColor, var1, 931, 786
PixelGetColor, var2, 874, 810
if (var1=0x4141EA) && (var2=0xFFFFFF)
{
	Gosub, Middle
}
Gosub, Beginning

Middle:
Start = 39.980
Gui, +AlwaysOnTop +ToolWindow -SysMenu -Caption
Gui, Color, CCCCCC
Gui, Font, cFF0000 s20 , verdana
Gui, Add, Text, vD y0, %Start%
Gui, Show, NoActivate x0 y0,uptime
WinSet, TransColor, CCCCCC 255,uptime
StartTime := A_TickCount
SetTimer, End, 25
Return

End:
Seconds := Start - ((A_TickCount - StartTime)/1000)
GuiControl, , D, %Seconds%
Gui, Show, NoActivate x0 y0,uptime
If seconds < 0.025
{
	Gui, Hide
	SetTimer,, Off
	Gosub, Beginning
}
Return
Hope it's the right thread, new here lol
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help with a GUI script and an error I don't understand

24 Apr 2019, 22:38

Try this:
  • I do not run through the middle in a loop.
  • I only show the Gui instead.
  • not tested

Code: Select all

Middle:
Start = 39.980
Gui, +AlwaysOnTop +ToolWindow -SysMenu -Caption
Gui, Color, CCCCCC
Gui, Font, cFF0000 s20 , verdana
Gui, Add, Text, vD y0, %Start%
Gui, Show, NoActivate x0 y0,uptime
WinSet, TransColor, CCCCCC 255,uptime
StartTime := A_TickCount
SetTimer, End, 25
Return

Beginning:
PixelGetColor, var1, 931, 786
PixelGetColor, var2, 874, 810
if (var1=0x4141EA) && (var2=0xFFFFFF)
	Gui, Show
Gosub, Beginning

End:
Seconds := Start - ((A_TickCount - StartTime)/1000)
GuiControl, , D, %Seconds%
Gui, Show, NoActivate x0 y0,uptime
If seconds < 0.025
{
	Gui, Hide
	SetTimer,, Off
	Gosub, Beginning
}
Return
I hope that helps.
IMTIREDSHUTUP
Posts: 5
Joined: 24 Apr 2019, 22:03

Re: Help with a GUI script and an error I don't understand

24 Apr 2019, 23:11

Sadly, no. It seems to lock me out of the game I am in and make it so that I can't retab back in.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help with a GUI script and an error I don't understand

24 Apr 2019, 23:23

I suggest as next step to sort your spaghetti code. currently, the Beginning: is not reachable until the end.
IMTIREDSHUTUP
Posts: 5
Joined: 24 Apr 2019, 22:03

Re: Help with a GUI script and an error I don't understand

24 Apr 2019, 23:57

The beginning is run instantly right after the AHK is launched. The beginning actually loops until the two pixels are found in which it goes to "Middle:"
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help with a GUI script and an error I don't understand

25 Apr 2019, 00:30

No code exists to goto Middle. Middle is a misnomer now, rename it more appropriate like AutoStart, or better yet, delete the Label altogether. as I said, it is not used.

You also have an imbalance of gosubs and return. eg. Gosub, Beginning is called more often than it would find Returns.
IMTIREDSHUTUP
Posts: 5
Joined: 24 Apr 2019, 22:03

Re: Help with a GUI script and an error I don't understand

25 Apr 2019, 02:00

Pretty sure what you are saying is completely wrong. At the very beginning it autoreads "Beginning:" and if the two pixels align it has the code written, "Gosub, Middle." "Gosub, Beginning" is used more than "Return" because I want it to loop, not end. I have no clue what you are trying to say.
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Help with a GUI script and an error I don't understand

25 Apr 2019, 05:15

To get rid of the error you can use:

Code: Select all

If seconds < 0.025
{
	Gui, Destroy ; instead of Hide to destroy the window
	SetTimer,, Off
	Gosub, Beginning
}
BTW: Calling Beginning: from inside its code might cause severe errors. You'd better use a loop or a timer.
IMTIREDSHUTUP
Posts: 5
Joined: 24 Apr 2019, 22:03

Re: Help with a GUI script and an error I don't understand

25 Apr 2019, 18:57

Sadly, destroying the GUI instead of hiding it doesnt do anything. D: -Error still occurs
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Help with a GUI script and an error I don't understand

25 Apr 2019, 19:53

At the end of the script, you're going back to the beginning, which goes to the middle, which defines the GUI all over again with the same control name. Try defining the GUI at the top of the script, before the beginning, and then only show and update it later in the script, like so (untested):

Code: Select all

Gui, +AlwaysOnTop +ToolWindow -SysMenu -Caption
Gui, Color, CCCCCC
Gui, Font, cFF0000 s20 , verdana
Gui, Add, Text, vD y0, %Start%

Beginning:
PixelGetColor, var1, 931, 786
PixelGetColor, var2, 874, 810
if (var1=0x4141EA) && (var2=0xFFFFFF)
{
	Gosub, Middle
}
Gosub, Beginning

Middle:
Start = 39.980
GuiControl, , D, %Start%
Gui, Show, NoActivate x0 y0,uptime
WinSet, TransColor, CCCCCC 255,uptime
StartTime := A_TickCount
SetTimer, End, 25
Return

End:
Seconds := Start - ((A_TickCount - StartTime)/1000)
GuiControl, , D, %Seconds%
Gui, Show, NoActivate x0 y0,uptime
If seconds < 0.025
{
	Gui, Hide
	SetTimer,, Off
	Gosub, Beginning
}
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 262 guests