Pause game - change settings and resume

Ask gaming related questions (AHK v1.1 and older)
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Pause game - change settings and resume

30 Oct 2013, 22:39

I've created a game in AHK that displays pictures with the options of adding text or audio. The Gui destroys itself and reloads fresh pictures every turn. I wanted a method to quickly change the settings that control what is displayed. I created a separate Settings Gui. It sends results to a text file that is then used when recreating the Game Gui. Everything works as expected except reloading the Settings GUI. If I use WinWaitclose to pause the Game Gui then I can't reload the settings Gui (it only loads once). Below is the code for the Settings Function followed by the code from the main Gui to activate it. Can someone please suggest a fix, thanks.

Code: Select all

Settings()
{
	WinClose, Touch The Picture ; the game GUI
	
	Global FileToLoad, nUP, DIS, STY, TYP
	
	Static MF := Ceil((CalcFontSize("This is some dummy text")/ 3.5) * 100/A_ScreenDPI)	; Settings font size	
	Static MS := MF / 1.5

	static Load, Exit, Quit,
	Static PicText, QutText
	Static OrderRandom, OrderSequential
	Static Show2, Show3, Show4, Show5, Show6, Show7, Show8, Show9, Show10
	Static HintSound, HintWord, HintBoth
	Static ClearScreen, ClearList
	
	Gui, 10: -Caption +ToolWindow  +Alwaysontop -DPIscale Border
	Gui, 10:Color, cFF9900, white
	Gui, 10:margin, 20,20
	
	Gui, 10:font, s%MS% bold
	Gui, 10:add, text, ,Select:
	Gui, 10:add, text, x+0 vPicText, Pictures To Show:

	Gui, 10:font, s%MF% normal
	Gui, 10:margin, 10,10
	Gui, 10:add, button, x20 gLoad vLoad, Load List
	
	Gui, 10:margin, 10,30
	Gui, 10:font, s%MS% bold
	Gui, 10:add, text, ,Hint Type:
	
	Gui, 10:font, s%MF% normal
	Gui, 10:margin, 10,10
	
	GuiControlget, Load, 10:pos
	ButY := LoadH *.8

	Gui, 10:add, radio, x20 h%ButY% gHintType vHintSound 0x1000, Sound 
	Gui, 10:add, radio, x20 h%ButY% gHintType vHintWord 0x1000, Word
	Gui, 10:add, radio, x20 h%ButY% gHintType vHintBoth 0x1000, Both
	
	Gui, 10:margin, 10,30
	Gui, 10:font, s%MS% bold
	Gui, 10:add, text, x20 ,Display Order:
	
	Gui, 10:font, s%MF% normal
	Gui, 10:margin, 10,12
	
	Gui, 10:add, radio, x20 h%ButY% gOrderDis vOrderRandom 0x1000, Random
	Gui, 10:add, radio, x20 h%ButY% gOrderDis vOrderSequential 0x1000, Sequential
	
	Gui, 10:margin, 10,30
	Gui, 10:font, s%MS% bold
	Gui, 10:add, text, x20 ,Game Style:
	
	Gui, 10:font, s%MF% normal
	Gui, 10:margin, 10,12
	
	Gui, 10:add, radio, x20 h%ButY% 0x1000 gClearSty vClearScreen, Clear Screen
	Gui, 10:add, radio, x20 h%ButY% 0x1000 gClearSty vClearList, Clear List
	
	ButY := Ceil(LoadH * 1.5)
	Gui, 10:add, button, x20 y+20 h%ButY% gExit vExit, Exit Menu
	Gui, 10:margin, 20,20
		
	Guicontrolget, ClearScreen, 10:Pos
	
	ButX := ClearScreenX + ClearScreenW + 20
	GuiControl, 10:move, Load, w%ClearScreenW%
	
	Guicontrolget, Load, 10:Pos
	Guicontrolget, PicText, 10:Pos
	
	GuiControl, 10:move, PicText, x%ButX%
	
	gap = 23
	
	Gui, 10:add, radio, x%ButX% y%LoadY% w%PicTextW% h%LoadH% gShowPics vShow2 0x1000, 2
	Gui, 10:add, radio, y+%gap% w%PicTextW% h%LoadH% gShowPics vShow3  0x1000, 3
	Gui, 10:add, radio, y+%gap% w%PicTextW% h%LoadH% gShowPics vShow4  0x1000, 4
	Gui, 10:add, radio, y+%gap% w%PicTextW% h%LoadH% gShowPics vShow5 0x1000, 5
	Gui, 10:add, radio, y+%gap% w%PicTextW% h%LoadH% gShowPics vShow6 0x1000, 6
	Gui, 10:add, radio, y+%gap% w%PicTextW% h%LoadH% gShowPics vShow7  0x1000, 7
	Gui, 10:add, radio, y+%gap% w%PicTextW% h%LoadH% gShowPics vShow8  0x1000, 8
	Gui, 10:add, radio, y+%gap% w%PicTextW% h%LoadH% gShowPics vShow9  0x1000, 9
	Gui, 10:add, radio, y+%gap% w%PicTextW% h%LoadH% gShowPics vShow10 0x1000, 10
		
	Guicontrolget, Load, 10:Pos
	GuiControl, 10:move, Exit, w%ClearScreenW%
	GuiControl, 10:move, OrderRan, w%ClearScreenW%
	GuiControl, 10:move, OrderSeq, w%ClearScreenW%
	GuiControl, 10:move, HintSound, w%ClearScreenW%
	GuiControl, 10:move, HintWord, w%ClearScreenW%
	GuiControl, 10:move, HintBoth, w%ClearScreenW%
	GuiControl, 10:move, ClearList, w%ClearScreenW%
	
	GuiControl, 10:, Show%nUP%, 1
	GuiControl, 10:, %TYP%, 1
	GuiControl, 10:, %DIS%, 1
	GuiControl, 10:, %STY%, 1

	Gui, 10:show, AutoSize, Current Settings

	WinWaitActive, Current Settings ; wait for the 'last found window' (i.e. the Gui) to be active
	WinWaitClose, Current Settings  ; wait for the 'last found window' (i.e. the Gui) to be destroyed

	GoSub Restart ; goes to the main script and recreates the game gui

	Return
	
	Load:
	
		Gui, 10:hide
		FileSelectFile, LoadFile, 3, lists
		
		if LoadFile !=
		FileToLoad := LoadFile
		
		Gui, 10:show
	
	Return
	
	Exit:
		
		FileAppend, %FileToLoad%`n, Settings\Temp
		FileAppend, %nUP%`n, Settings\Temp	;Pictures to show
		FileAppend, %TYP%`n, Settings\Temp	;Hint Type (Sound, Word or both)
		FileAppend, %DIS%`n, Settings\Temp	;Order (random or sequential)
		FileAppend, %STY%`n, Settings\Temp	;Clear (Screen or List)
		
		FileMove, Settings\Temp, Settings\Touch The Picture.txt, 1
			
		Gui, 10:destroy
		;GoSub Restart
	
	Return
	
	ClearSty:
	
		GuiControlGet, Btn, FocusV
		STY := Btn		
		
	return
	
	HintType:
	
		GuiControlGet, Btn, FocusV
		TYP := Btn		
		
	return	
	
	OrderDis:
	
		GuiControlGet, Btn, FocusV
		DIS := Btn		
		
	return	
	
	ShowPics:
	
		GuiControlGet, Btn, FocusV
		stringtrimleft, nUP, Btn, 4
		
	return	
}

;click the top left hand cornet to bring up settings:

	~lbutton::
		
		ifwinnotexist, Current Settings
		{
			MousegetPos, xpos, ypos 
			if (ypos < 100) and (xpos < 100)
			if (A_PriorHotkey == A_ThisHotkey AND A_TimeSincePriorHotkey < 350) 
			{
				Settings()
			}
		}
		else
		soundbeep

	return

I don't even get a Soundbeep!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 95 guests