Sign in to follow this  
Followers 0
anony10

New form problems

6 posts in this topic

#1 ·  Posted (edited)

Hello!

Yea, im again.

I have a new problem.I working on a tinyrpg, but i have a big bug.Example: you click on the "Infóim" button, it is works.But if you try to click on any button, it doesnt work.Okay, you exit form the program, run again, works.How can i fix it? (it is do with all of the buttons, so you cant click two withouth esc, and run again...)I tryied with Exitloop after GuiDelete commands, but nothing.

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <GUIListBox.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

InetGet("http://anony10.ucoz.com/rpg/ver.ini", @ScriptDir & "\ver.ini")

$ver = IniRead(@ScriptDir & "\ver.ini", "section", "key", "1.0")

If $ver > 1.0 Then

InetGet("http://anony10.ucoz.com/rpg/TinyRPG.au3", @ScriptDir & "\TinyRPG.exe")

EndIf

FileDelete(@ScriptDir & "\ver.ini")

IniRead(@AppDataDir & "\rpg.ini", "xp", "key", "0")

IniRead(@AppDataDir & "\rpg.ini", "nextlevel", "key", "50")

IniRead(@AppDataDir & "\rpg.ini", "level", "key", "1")

IniRead(@AppDataDir & "\rpg.ini", "zen", "key", "4500")

$level = 1

$xp = 0

$zen = 4500

$nextlevel = 50

$nev = IniRead (@AppDataDir & "\rpg.ini", "section", "key", "name")

If $nev = "name" Then

$neved = InputBox ("Írd be a neved", "Írd be a neved")

IniWrite(@AppDataDir & "\rpg.ini", "section", "key", $neved)

EndIf

;-------------------MAIN---------------------------------------

#Region ### START Koda GUI section ### Form=

$neved = IniRead(@AppDataDir & "\rpg.ini", "section", "key", "name")

$Form1 = GUICreate("Tiny RPG", 574, 275, 192, 124)

$Pic1 = GUICtrlCreatePic("", 36, 21, 110, 153, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))

$Button1 = GUICtrlCreateButton("Infóim", 53, 206, 75, 25, 0)

$List1 = GUICtrlCreateList("A farkashegy (6:00)", 208, 20, 102, 123)

GuiCtrlSetData($List1, "A pásztorgyermek (4:00)")

$Button2 = GUICtrlCreateButton("Indítás", 223, 175, 75, 25, 0)

$Label1 = GUICtrlCreateLabel($neved, 44, 182, 93, 17)

$help = GUICtrlCreateButton("?", 537, 242, 34, 30, 0)

$friss = GUICtrlCreateButton("Frissítés", 461, 244, 75, 26, 0)

$Label2 = GUICtrlCreateLabel("", 216, 151, 86, 17)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

;------------------MAIN-----------------------------------------

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

;-----------------------------------------------------------küldik

Case $Button2

$list = GuiCtrlRead($list1)

If $list = "A farkashegy (6:00)" Then

$countdown = 6 ;minutes for countdown

$seconds = $countdown * 60 ;convert to seconds

Countdown()

AdlibRegister("Countdown", 1000)

EndIf

If $list = "A pásztorgyermek (4:00)" Then

$countdown = 4 ;minutes for countdown

$seconds = $countdown * 60 ;convert to seconds

Countdown()

AdlibRegister("Countdown", 1000)

EndIf

;-----------------------------------------------------------infók

Case $Button1

$xp1 = IniRead(@AppDataDir & "\rpg.ini", "xp", "key", "0")

$nextlevel1 =IniRead(@AppDataDir & "\rpg.ini", "nextlevel", "key", "50")

$level1 = IniRead(@AppDataDir & "\rpg.ini", "level", "key", "1")

$zen1 = IniRead(@AppDataDir & "\rpg.ini", "zen", "key", "4500")

$Form2 = GUICreate("", 202, 193, 192, 124)

$Button1 = GUICtrlCreateButton("Bezárás", 0, 169, 75, 25, 0)

$Label1 = GUICtrlCreateLabel("Level = "& $level1, 17, 19, 160, 17)

$Label2 = GUICtrlCreateLabel("XP = " & $xp1, 18, 41, 160, 17)

$Label3 = GUICtrlCreateLabel("Köv. szintig = "& $nextlevel1, 18, 62, 160, 17)

$Label4 = GUICtrlCreateLabel("Zen = "& $zen1, 17, 84, 160, 17)

GUISetState(@SW_SHOW)

While 2

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

GuiDelete($Form2)

EndSwitch

WEnd

Case $friss

InetGet("http://anony10.ucoz.com/rpg/ver.ini", @ScriptDir & "\ver.ini")

$ver = IniRead(@ScriptDir & "\ver.ini", "section", "key", "1.0")

If $ver > 1.0 Then

InetGet("http://anony10.ucoz.com/rpg/TinyRPG.au3", @ScriptDir & "\TinyRPG.exe")

msgbox(0, "Frissítve", "Frissítve!")

EndIf

Case $help

#Region ### START Koda GUI section ### Form=

$Form5 = GUICreate("", 366, 226, 192, 124)

$Label1 = GUICtrlCreateLabel("Tiny RPG - bye Anony", 124, 28, 109, 17)

$Label2 = GUICtrlCreateLabel("Készítette: Anony", 69, 56, 87, 17)

$Label3 = GUICtrlCreateLabel("Fejleszti: Anony", 70, 74, 77, 17)

$Label4 = GUICtrlCreateLabel("A programot mindíg fejlesztem, de mindíg magától", 69, 120, 236, 17)

$Label5 = GUICtrlCreateLabel("frissíti magát, szóval nem kell ezmaitt aggódni.", 69, 138, 220, 17)

$Button1 = GuiCtrlCreateButton ("X", 22, 22, 22, 22)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

GuiDelete($Form5)

EndSwitch

WEnd

;---------------------------------------------------------------infók

EndSwitch

WEnd

Func Countdown()

Local $sec, $min, $hr

$sec = Mod($seconds, 60)

$min = Mod($seconds / 60, 60)

$hr = Floor($seconds / 60 ^ 2)

GUICtrlSetData($label2, StringFormat("%02i:%02i:%02i", $hr, $min, $sec))

If $seconds <= 0 Then

GuiCtrlRead($xp)

GuiCtrlRead($level)

GuiCtrlRead($nextlevel)

GuiCtrlRead($zen)

IF $xp <= $nextlevel Then

$xp = $xp + Random(25, 95, 0)

$zen = $zen + Random(120, 450, 0)

msgbox(0, "XP", "XP-t kaptál!")

IniWrite(@AppDataDir & "\rpg.ini", "xp", "key", $xp)

IniWrite(@AppDataDir & "\rpg.ini", "nextlevel", "key", $nextlevel)

IniWrite(@AppDataDir & "\rpg.ini", "level", "key", $level)

IniWrite(@AppDataDir & "\rpg.ini", "zen", "key", $zen)

EndIF

IF $xp >= $nextlevel Then

$nextlevel = Round($xp * 1.15, 0)

$level = $level + 1

$zen = $zen + Random (150, 600, 0)

msgbox (0, "Level up!", "Level up!Bónusz zen szint lépés miatt.")

IniWrite(@AppDataDir & "\rpg.ini", "xp", "key", $xp)

IniWrite(@AppDataDir & "\rpg.ini", "nextlevel", "key", $nextlevel)

IniWrite(@AppDataDir & "\rpg.ini", "level", "key", $level)

IniWrite(@AppDataDir & "\rpg.ini", "zen", "key", $zen)

EndIf

AdlibUnRegister("Countdown")

EndIf

$seconds -= 1

EndFunc

Sry for quote but it is bugging in code:O I dont know why.

PLz help!!: D

Edited by anony10

Share this post


Link to post
Share on other sites



anony10,

You are reusing the same variables for controls on different GUIs. For example, you use $Button1 when you create the "Infóim" button on $Form1 - you then overwrite the value when you create the "Bezárás" button on $Form2. When you return to the main While...WEnd loop, you will never see the original value of the earlier button and so it will never be actioned. ;)

Just give your controls unique names and you will find that your buttons stay responsive. All clear? :graduated:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

ookay, but i dont understand you fully. buuut it is possible to fix it?

Share this post


Link to post
Share on other sites

anony10,

Let me try to explain more clearly. ;)

When you create a control AutoIt gives it a unique ControlID and GUIGetMsg returns this ControlID when you action the control.

You first define $Button1 here:

#Region ### START Koda GUI section ### Form=
    $neved = IniRead(@Scriptdir & "rpg.ini", "section", "key", "name")
    $Form1 = GUICreate("Tiny RPG", 574, 275, 192, 124)
    $Pic1 = GUICtrlCreatePic("", 36, 21, 110, 153, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
    $Button1 = GUICtrlCreateButton("Infóim", 53, 206, 75, 25, 0) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

and the value of $Button1 is set to 4 when I run your script. So each time you action that particular button, GUIGetMsg returns 4 and in your Switch statement the Case $Button1 code is run when this happens.

However, you overwrite the variable when you create $Form2:

$Form2 = GUICreate("", 202, 193, 192, 124)
$Button1 = GUICtrlCreateButton("Bezárás", 0, 169, 75, 25, 0) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

You now have $Button1 set to 11 as the new control returns a different ControlID. This works fine while $Form2 is displayed and you are using this GUIGetMsg loop:

While 2
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUIDelete($Form2)
            ExitLoop
    EndSwitch
WEnd

because the button you want to press has the correct ControlID (11).

However, when you return to the main GUIGetMsg loop, $Button1 is still set to 11. But you have deleted the button with that ControlID and you want to action the original button with a ControlID of 4. However, your Case $Button1 is now looking for 11 and GUIGetMsg is returning 4 when you press the button - so no match and an unresponsive button. ;)

Clearer now? :graduated:

Solution

As I mentioned above, the solution is to use unique names for your controls so that you do not overwrite existing values. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Okay i think i understand you.

edit:

With exitloop works fine but when i click "Infóim" then "Bezárás" and i try to click for example "A farkashegy (6:00)" then the countdown doesnt works.

Edited by anony10

Share this post


Link to post
Share on other sites

anony10,

Try this version of your script with unique variables to hold the ControlIDs returned by the controls: ;)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("TrayIconDebug", 1)

;InetGet("http://anony10.ucoz.com/rpg/ver.ini", @ScriptDir & "\ver.ini")
$ver = IniRead(@ScriptDir & "\ver.ini", "section", "key", "1.0")
If $ver > 1.0 Then
    ;InetGet("http://anony10.ucoz.com/rpg/TinyRPG.au3", @ScriptDir & "\TinyRPG.exe")
EndIf
FileDelete(@ScriptDir & "\ver.ini")
IniRead(@Scriptdir & "\rpg.ini", "xp", "key", "0")
IniRead(@Scriptdir & "\rpg.ini", "nextlevel", "key", "50")
IniRead(@Scriptdir & "\rpg.ini", "level", "key", "1")
IniRead(@Scriptdir & "\rpg.ini", "zen", "key", "4500")

$level = 1
$xp = 0
$zen = 4500
$nextlevel = 50
$nev = IniRead(@Scriptdir & "\rpg.ini", "section", "key", "name")

If $nev = "name" Then
    $neved = InputBox("Írd be a neved", "Írd be a neved")
    IniWrite(@Scriptdir & "\rpg.ini", "section", "key", $neved)
EndIf

;-------------------MAIN---------------------------------------
#Region ### START Koda GUI section ### Form=
    $neved = IniRead(@Scriptdir & "\rpg.ini", "section", "key", "name")
    $Form1 = GUICreate("Tiny RPG", 574, 275, 192, 124)
    $Pic11 = GUICtrlCreatePic("", 36, 21, 110, 153, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
    $Button11 = GUICtrlCreateButton("Infóim", 53, 206, 75, 25, 0)
    $List11 = GUICtrlCreateList("A farkashegy (6:00)", 208, 20, 102, 123)
    GUICtrlSetData($List11, "A pásztorgyermek (4:00)")
    $Button12 = GUICtrlCreateButton("Indítás", 223, 175, 75, 25, 0)
    $Label11 = GUICtrlCreateLabel($neved, 44, 182, 93, 17)
    $help = GUICtrlCreateButton("?", 537, 242, 34, 30, 0)
    $friss = GUICtrlCreateButton("Frissítés", 461, 244, 75, 26, 0)
    $Label12 = GUICtrlCreateLabel("", 216, 151, 86, 17)
    GUISetState(@SW_SHOW)
#Endregion ### END Koda GUI section ###
;------------------MAIN-----------------------------------------

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

            ;-----------------------------------------------------------küldik
        Case $Button12
            $list = GUICtrlRead($List11)

            If $list = "A farkashegy (6:00)" Then
                $countdown = 6 ;minutes for countdown
                $seconds = $countdown * 60 ;convert to seconds
                Countdown()
                AdlibRegister("Countdown", 1000)
            EndIf
            If $list = "A pásztorgyermek (4:00)" Then
                $countdown = 4 ;minutes for countdown
                $seconds = $countdown * 60 ;convert to seconds
                Countdown()
                AdlibRegister("Countdown", 1000)
            EndIf

            ;-----------------------------------------------------------infók
        Case $Button11
            $xp1 = IniRead(@Scriptdir & "\rpg.ini", "xp", "key", "0")
            $nextlevel1 = IniRead(@Scriptdir & "\rpg.ini", "nextlevel", "key", "50")
            $level1 = IniRead(@Scriptdir & "\rpg.ini", "level", "key", "1")
            $zen1 = IniRead(@Scriptdir & "\rpg.ini", "zen", "key", "4500")
            $Form2 = GUICreate("", 202, 193, 192, 124)
            $Button21 = GUICtrlCreateButton("Bezárás", 0, 169, 75, 25, 0)
            $Label21 = GUICtrlCreateLabel("Level = " & $level1, 17, 19, 160, 17)
            $Label22 = GUICtrlCreateLabel("XP = " & $xp1, 18, 41, 160, 17)
            $Label23 = GUICtrlCreateLabel("Köv. szintig = " & $nextlevel1, 18, 62, 160, 17)
            $Label24 = GUICtrlCreateLabel("Zen = " & $zen1, 17, 84, 160, 17)
            GUISetState(@SW_SHOW)

            While 2
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        Exit
                    Case $Button21
                        GUIDelete($Form2)
                        ExitLoop
                EndSwitch
            WEnd

        Case $friss
            ;InetGet("http://anony10.ucoz.com/rpg/ver.ini", @ScriptDir & "\ver.ini")
            $ver = IniRead(@ScriptDir & "\ver.ini", "section", "key", "1.0")
            If $ver > 1.0 Then
                ;InetGet("http://anony10.ucoz.com/rpg/TinyRPG.au3", @ScriptDir & "\TinyRPG.exe")
                MsgBox(0, "Frissítve", "Frissítve!")
            EndIf
        Case $help
            #Region ### START Koda GUI section ### Form=
                $Form5 = GUICreate("", 366, 226, 192, 124)
                $Label51 = GUICtrlCreateLabel("Tiny RPG - bye Anony", 124, 28, 109, 17)
                $Label52 = GUICtrlCreateLabel("Készítette: Anony", 69, 56, 87, 17)
                $Label53 = GUICtrlCreateLabel("Fejleszti: Anony", 70, 74, 77, 17)
                $Label54 = GUICtrlCreateLabel("A programot mindíg fejlesztem, de mindíg magától", 69, 120, 236, 17)
                $Label55 = GUICtrlCreateLabel("frissíti magát, szóval nem kell ezmaitt aggódni.", 69, 138, 220, 17)
                $Button51 = GUICtrlCreateButton("X", 22, 22, 22, 22)
                GUISetState(@SW_SHOW)
            #Endregion ### END Koda GUI section ###

            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        Exit
                    Case $Button51
                        GUIDelete($Form5)
                EndSwitch
            WEnd
            ;---------------------------------------------------------------infók
    EndSwitch
WEnd

Func Countdown()
    Local $sec, $min, $hr
    $sec = Mod($seconds, 60)
    $min = Mod($seconds / 60, 60)
    $hr = Floor($seconds / 60 ^ 2)
    GUICtrlSetData($Label12, StringFormat("%02i:%02i:%02i", $hr, $min, $sec))
    If $seconds <= 0 Then
        GUICtrlRead($xp)
        GUICtrlRead($level)
        GUICtrlRead($nextlevel)
        GUICtrlRead($zen)
        If $xp <= $nextlevel Then
            $xp = $xp + Random(25, 95, 0)
            $zen = $zen + Random(120, 450, 0)
            MsgBox(0, "XP", "XP-t kaptál!")
            IniWrite(@Scriptdir & "\rpg.ini", "xp", "key", $xp)
            IniWrite(@Scriptdir & "\rpg.ini", "nextlevel", "key", $nextlevel)
            IniWrite(@Scriptdir & "\rpg.ini", "level", "key", $level)
            IniWrite(@Scriptdir & "\rpg.ini", "zen", "key", $zen)
        EndIf
        If $xp >= $nextlevel Then
            $nextlevel = Round($xp * 1.15, 0)
            $level = $level + 1
            $zen = $zen + Random(150, 600, 0)
            MsgBox(0, "Level up!", "Level up!Bónusz zen szint lépés miatt.")
            IniWrite(@Scriptdir & "\rpg.ini", "xp", "key", $xp)
            IniWrite(@Scriptdir & "\rpg.ini", "nextlevel", "key", $nextlevel)
            IniWrite(@Scriptdir & "\rpg.ini", "level", "key", $level)
            IniWrite(@Scriptdir & "\rpg.ini", "zen", "key", $zen)
        EndIf
        AdlibUnRegister("Countdown")
    EndIf
    $seconds -= 1
EndFunc   ;==>Countdown

The countdown works for me. :graduated:

M23

Note: I disabled the InetGet lines. :)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0