LiewView and multiple windows help needed

Ask gaming related questions (AHK v1.1 and older)
autohost
Posts: 11
Joined: 03 May 2021, 15:18

LiewView and multiple windows help needed

Post by autohost » 03 May 2021, 15:50

Here is a subset of the program I'm working on that demonstrates the issues I'm currently fighting.

1. The 3 LV_Modify lines near the bottom do not update the ListView in the main window, but the other 3 LV_Modify lines further up do work.
2. After BidButtonNext is called, the main game window seems to disappear (sinks under other programs' windows) instead of staying at the same level it was before.

Thank you for your time and constructive help ;)

-----------------------------------------

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.


Num_Players := 2
Player1 := "Harry"
Player2 := "Sally"

Loop , %Num_Players% {
	Var := "Player" . A_Index
	cols .= "|" . %Var%
	Player%A_Index%Score := 0
	Player%A_Index%Bid := 0
}

Gui,New, +HwndMyGuiHwnd, Up and Down the River
Gui, %MyGuiHwnd%:Default
	
Gui,Add,ListView,R14 NoSortHdr Grid ReadOnly w500 vMLV, Deal|Turn#%cols%
	
Turn1 := 7
Turn2 := 6
Turn3 := 5
Turn4 := 4
Turn5 := 3
Turn6 := 2
Turn7 := 1
Turn8 := 2
Turn9 := 3
Turn10 := 4
Turn11 := 5
Turn12 := 6
Turn13 := 7
	
Try = 1
	
	
Loop, 13 {
	; Each row needs Dealer, Turn#, "Player1Bid,Player1Score", "Player2Bid,Player2Score", "Player3Bid,Player3Score" etc
	
	if (Try > Num_Players) {
		Try = 1
	}
	Dealer := SubStr(Player%Try%,1,1)
	Try++
	LV_Add(AutoHDR,Dealer,Turn%A_Index%,"0 0","0 0","0 0","0 0","0 0","0 0","0 0","0 0")
}

Turn := 1
Player := 1
Bid := 0
Gui Add, Button,y+10 gStartBids, Start Bids
Gui,Show
return

StartBids:
LV_Modify(3,,,,"4 25")		;These 3 lines DO get updated in the ListView
LV_Modify(4,,,,"2 15")
LV_Modify(5,,,,"1 5")
Gui Bid:+owner%MyGuiHwnd%   ;set owner to the main window
Gui +Disabled		;disable main window
Gui,Bid:Add,Text,,What is Player%Player%'s bid for Turn %Turn%?
Gui,Bid:Add,Edit,x164 y0 W30 ReadOnly
Gui,Bid:Add,UpDown,Range0-7 vP_Bid, 0
Gui,Bid:Add,Button,x87 y25 w43 h23, Next
Gui,Bid:Show
return

BidButtonNext:
Gui, Bid:Submit
Gui, %MyGuiHwnd%:-Disabled  ; Re-enable the main window (must be done prior to the next step).
Gui, Bid:Destroy
MsgBox Bid is %P_Bid%
;LV_Modify(%Turn%,,,%P_Bid% . " score")
LV_Modify(6,,,,"6 55")		;These 3 lines do not get updated in the ListView
LV_Modify(7,,,,"7 15")
LV_Modify(8,,,,"8 5")
;GuiControl, +Redraw, MLV  ;no effect
return

GuiClose:
ExitApp

--------------------------------------------
Last edited by BoBo on 03 May 2021, 15:57, edited 1 time in total.
Reason: Moved to Gaming section.

User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: LiewView and multiple windows help needed

Post by mikeyww » 03 May 2021, 16:04

Specify the default GUI in the routine.

Code: Select all

Gui, %MyGuiHwnd%:Default
Gui, Show
Last edited by mikeyww on 03 May 2021, 16:07, edited 1 time in total.

autohost
Posts: 11
Joined: 03 May 2021, 15:18

Re: LiewView and multiple windows help needed

Post by autohost » 03 May 2021, 16:06

I did specify that exact line under the Gui, New line.

User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: LiewView and multiple windows help needed

Post by mikeyww » 03 May 2021, 16:08

in the routine: the same routine as the LV_Modify. I am referring to a labeled subroutine.

Code: Select all

Gui, %MyGuiHwnd%:Default
Gui, Show
Explained: GUI threads

autohost
Posts: 11
Joined: 03 May 2021, 15:18

Re: LiewView and multiple windows help needed

Post by autohost » 03 May 2021, 17:56

Thank you, that did it!

autohost
Posts: 11
Joined: 03 May 2021, 15:18

Re: LiewView and multiple windows help needed

Post by autohost » 03 May 2021, 18:27

When I try to do LV_Modify with variables, it doesn't work. The MsgBox line shows that the %Turn% and %P_Bid% vars are set just fine.

Same code as above, but with the changes you mentioned.

Code: Select all

BidButtonNext:
Gui, Bid:Submit
Gui, %MyGuiHwnd%:-Disabled  ; Re-enable the main window (must be done prior to the next step).
Gui, Bid:Destroy
Gui, %MyGuiHwnd%:Default
MsgBox Turns = %Turn% and Player = %Player%  P_Bid = %P_Bid%
if (Player = 1) {
	LV_Modify(%Turn%,,,,%P_Bid%)
}
Gui, Show

User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: LiewView and multiple windows help needed

Post by mikeyww » 03 May 2021, 18:30

Whereas AHK commands accept literal strings as parameters, functions such as LV_Modify accept expressions such as Turn, rather than %Turn% (in the most common usages).

Explained: Expressions

Demonstration:

Code: Select all

table := 5.6
Turn := "table"
MsgBox, 0, A, % Round(table)
MsgBox, 0, B, % Round(%Turn%)
MsgBox, 0, C, % Round(Turn)
MsgBox, 0, D, % Round(%table%)

autohost
Posts: 11
Joined: 03 May 2021, 15:18

Re: LiewView and multiple windows help needed

Post by autohost » 03 May 2021, 18:55

Thank you!

Player 1 is 4th column in the ListView, Player 2 is the 5th column, etc
LV_Modify(Turn,,,,P_Bid . " " . Score)

How do I 'insert' the appropriate number of commas in the LV_Modify function to correctly modify that player's cell?

At the moment, I could do it with a bunch of IF statements, with a different LV_Modify for every IF to handle each player number, but there should be an easier way to do it.

Code: Select all

if (Player = 1) {
	LV_Modify(Turn,,,,P_Bid . "  " . Score)
}
if (Player = 2) {
	LV_Modify(Turn,,,,,P_Bid . "  " . Score)
}
if (Player = 3) {
	LV_Modify(Turn,,,,,,P_Bid . "  " . Score)
}
if (Player = 4) {
	LV_Modify(Turn,,,,,,,P_Bid . "  " . Score)
}
if (Player = 5) {
	LV_Modify(Turn,,,,,,,,P_Bid . "  " . Score)
}
if (Player = 6) {
	LV_Modify(Turn,,,,,,,,,P_Bid . "  " . Score)
}
if (Player = 7) {
	LV_Modify(Turn,,,,,,,,,,P_Bid . "  " . Score)
}
if (Player = 8) {
	LV_Modify(Turn,,,,,,,,,,,P_Bid . "  " . Score)
}

User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: LiewView and multiple windows help needed

Post by mikeyww » 03 May 2021, 19:13

In your posted script, click on "LV_Modify", and see where it indicates, "The ColN option may be used to update specific columns without affecting the others."

autohost
Posts: 11
Joined: 03 May 2021, 15:18

Re: LiewView and multiple windows help needed

Post by autohost » 03 May 2021, 19:49

Thank you, got that to work, except strange that I had to put quotes around the ColN option.

User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: LiewView and multiple windows help needed

Post by mikeyww » 03 May 2021, 20:01

An expression representing a text string would be quoted as usual.

Glad it worked out!

autohost
Posts: 11
Joined: 03 May 2021, 15:18

Re: LiewView and multiple windows help needed

Post by autohost » 03 May 2021, 20:17

I have a button for which the text on it includes a variable. How do I 'update' or 'refresh' the window, so that the button correctly displays its text with the new value in the variable?
GuiControl, MoveDraw? It says it can redraw.

User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: LiewView and multiple windows help needed

Post by mikeyww » 03 May 2021, 20:20

Code: Select all

Gui, Font, s10
Gui, Add, Button,, Original
Gui, Show
SoundBeep, 1500
Sleep, 1000
SoundBeep, 1000
GuiControl,, Original, New
Explained: GuiControl

Or:

Code: Select all

string = Original
Gui, Font, s10
Gui, Add, Button, w200 vttext
Gui, Show
buttonUpdate("ttext", string)
SoundBeep, 1500
Sleep, 1000
SoundBeep, 1000
string = New
buttonUpdate("ttext", string)

buttonUpdate(var, string) {
 GuiControl,, %var%, %string%
}

autohost
Posts: 11
Joined: 03 May 2021, 15:18

Re: LiewView and multiple windows help needed

Post by autohost » 03 May 2021, 21:35

Again, thanks, I appreciate your time and patience.

Post Reply

Return to “Gaming Help (v1)”