GuiControlGet Problem Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
yawikflame
Posts: 21
Joined: 02 Jan 2017, 06:19
Contact:

GuiControlGet Problem

14 Jan 2017, 08:41

As this is my first question in the forum, i will try being as concise as possible:

a little background:
While trying to create a "MiniGame" of card memorization, i tried asking the player to select 3 cards in which later on he will have to remember.
i already managed counting the first three clicks and having boxes showing each click as "First/Second/Third Card = "
but i failed to store any value/string of the clicked item(picture = card) into variables.
i have seen something that might solve this using GuiControlGet but it always had errors when i tried running the code again.
the question:
how could i assign variables(for example a,b,c) to get the name(or value, rather) of the clicked card(represented by a picture)?



my code so far:

Code: Select all

#SingleInstance, Force
msgbox, Welcome To Memory!

;Gui Layout
;-----------------

Gui, Font, cAqua
Gui, Show, x600 y50 w700 h700, Memory
Gui, Color, Blue


Gui, Add, Text,cRed x10 y50, Instructions:
Gui, Add, Text, x10 y+7, Pick Three Cards

;Clubs
;----------------------

Gui, Add, Picture, x10 y105 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\2_of_clubs.png
Gui, Add, Picture, x+5 y105 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\3_of_clubs.png
Gui, Add, Picture, x+5 y105 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\4_of_clubs.png
Gui, Add, Picture, x+5 y105 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\5_of_clubs.png
Gui, Add, Picture, x+5 y105 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\6_of_clubs.png
Gui, Add, Picture, x+5 y105 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\7_of_clubs.png
Gui, Add, Picture, x+5 y105 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\8_of_clubs.png
Gui, Add, Picture, x+5 y105 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\9_of_clubs.png
Gui, Add, Picture, x+5 y105 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\10_of_clubs.png
Gui, Add, Picture, x+5 y105 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\jack_of_clubs2.png
Gui, Add, Picture, x+5 y105 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\queen_of_clubs2.png
Gui, Add, Picture, x+5 y105 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\king_of_clubs2.png


;Diamonds
;----------------------

Gui, Add, Picture, x10 y210 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\2_of_diamonds.png
Gui, Add, Picture, x+5 y210 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\3_of_diamonds.png
Gui, Add, Picture, x+5 y210 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\4_of_diamonds.png
Gui, Add, Picture, x+5 y210 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\5_of_diamonds.png
Gui, Add, Picture, x+5 y210 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\6_of_diamonds.png
Gui, Add, Picture, x+5 y210 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\7_of_diamonds.png
Gui, Add, Picture, x+5 y210 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\8_of_diamonds.png
Gui, Add, Picture, x+5 y210 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\9_of_diamonds.png
Gui, Add, Picture, x+5 y210 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\10_of_diamonds.png
Gui, Add, Picture, x+5 y210 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\jack_of_diamonds2.png
Gui, Add, Picture, x+5 y210 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\queen_of_diamonds2.png
Gui, Add, Picture, x+5 y210 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\king_of_diamonds2.png


;Hearts
;----------------------

Gui, Add, Picture, x10 y315 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\2_of_hearts.png
Gui, Add, Picture, x+5 y315 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\3_of_hearts.png
Gui, Add, Picture, x+5 y315 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\4_of_hearts.png
Gui, Add, Picture, x+5 y315 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\5_of_hearts.png
Gui, Add, Picture, x+5 y315 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\6_of_hearts.png
Gui, Add, Picture, x+5 y315 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\7_of_hearts.png
Gui, Add, Picture, x+5 y315 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\8_of_hearts.png
Gui, Add, Picture, x+5 y315 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\9_of_hearts.png
Gui, Add, Picture, x+5 y315 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\10_of_hearts.png
Gui, Add, Picture, x+5 y315 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\jack_of_hearts2.png
Gui, Add, Picture, x+5 y315 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\queen_of_hearts2.png
Gui, Add, Picture, x+5 y315 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\king_of_hearts2.png


;Spades
;----------------------

Gui, Add, Picture, x10 y420 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\2_of_spades.png
Gui, Add, Picture, x+5 y420 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\3_of_spades.png
Gui, Add, Picture, x+5 y420 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\4_of_spades.png
Gui, Add, Picture, x+5 y420 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\5_of_spades.png
Gui, Add, Picture, x+5 y420 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\6_of_spades.png
Gui, Add, Picture, x+5 y420 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\7_of_spades.png
Gui, Add, Picture, x+5 y420 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\8_of_spades.png
Gui, Add, Picture, x+5 y420 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\9_of_spades.png
Gui, Add, Picture, x+5 y420 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\10_of_spades.png
Gui, Add, Picture, x+5 y420 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\jack_of_spades2.png
Gui, Add, Picture, x+5 y420 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\queen_of_spades2.png
Gui, Add, Picture, x+5 y420 w50 h100 gPick, C:\Users\yawik\Desktop\AHK\test game\Memory\Playing Cards\king_of_spades2.png



Gui, Add, Picture, x0 y0 w700 h700, C:\Users\yawik\Desktop\AHK\test game\Memory\Memory.jpg



return
;Labels
;------------------

Pick:
	counter++
	if (counter = 1)
	{
		a := gPick  ;first pick
		GuiControlGet, a [, Picture, a, ]
		msgbox, First Card = %a%
		return
	}
	else if (counter = 2)
	{
		b := gPick  ;second pick
		msgbox, Second Card = %b%
		return
	}
	else if (counter = 3)
	{
		c := gPick  ;third pick
		msgbox, Third Card = %c%
		return
	}




GuiClose:
	ExitApp
	return
	
;Functions
;------------------





;Hotkeys
;------------------






return
Esc::ExitApp

thanks in advance!
yawik
just me
Posts: 9574
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GuiControlGet Problem  Topic is solved

14 Jan 2017, 12:41

Code: Select all

		GuiControlGet, a [, Picture, a, ]
The square brackets are used to mark optional parameters in the help file. Don't put them into real code.

Code: Select all

Pick:
	counter++
	if (counter = 1)
	{
		a := A_GuiControl  ;first pick
		msgbox, First Card = %a%
		return
	}
	else if (counter = 2)
	{
		b := A_GuiControl ;second pick
		msgbox, Second Card = %b%
		return
	}
	else if (counter = 3)
	{
		c := A_GuiControl ;third pick
		msgbox, Third Card = %c%
		return
	}
though it might be better to associate an own vName with each Pic control (Storing and Responding to User Input). A_GuiCOntrol will contain that Name (w/o the leading v) then.
User avatar
yawikflame
Posts: 21
Joined: 02 Jan 2017, 06:19
Contact:

Re: GuiControlGet Problem

14 Jan 2017, 16:26

"just me"
Danke Sehr!
MfG
yawik :D

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 386 guests