3
votes

I am trying to display and update a gui element (text string). Can someone tell me what I am doing wrong here? The initial text is never replaced by the updating text in the loop.

kills=0

#n::
Gui,Add,Text,vStatus, starting the killing
Gui,Show,w250 h375
Loop
{
GuiControl,,vStatus, killed %kills% Glorks!
kills+=1
Sleep,3000
}
return
1

1 Answers

6
votes

Here is working code:

kills=0

#n::
    Gui,Add,Text,vStatus, starting the killing
    Gui,Show,w250 h375, Glorks counter
    Loop
    {
        IfWinNotExist, Glorks counter
        {
            Gui, Destroy
            return
        }
        GuiControl,,Status, killed %kills% Glorks!
        kills+=1
        Sleep,3000
    }
return

Your mistakes:

  1. You should use Status instead of vStatus in GuiControl command.

  2. When you close GUI, you are not stopping loop, so IfWinNotExist detect if window exists and if not exists it will destroy all gui variables and exit from loop. So you can again press Win+n and start gui again.

Note: If you want to start count kills every time from 0 when gui is started then move kills=0 to right after #n::