Sign in to follow this  
Followers 0
Lord_Doominik

got a bug in a program

2 posts in this topic

hi, i've done a little program, where you can build something, like in a browsergame.

the onyl problem i have is, that you can't build anymore, if your gold is higher than 10 and i can't imagine why...

i'm sorry that the program is completely in german, but i hope you can understand it anyway. i just had no pleasure to translate all of the program...

here's the code:

;Name: Bauscript.au3
;Author: Lord_Doominik
;Status: In Progress (0%)
;Version: 0


#include <GuiConstants.au3>
#include <date.au3>

Global $Time, $Hour, $Min, $Sec

GuiCreate("MyGUI", 392, 323,(@DesktopWidth-392)/2, (@DesktopHeight-323)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$GLabel = GuiCtrlCreateLabel("Gold:", 70, 20, 30, 20)
$Gold = GuiCtrlCreateLabel("0", 100, 20, 90, 20)

$Kosten = GuiCtrlCreateLabel("Kosten", 150, 60, 50, 20)
$Zeit = GuiCtrlCreateLabel("Zeit", 200, 60, 50, 20)

$RLevel = GuiCtrlCreateLabel("1", 50, 90, 70, 20)
$RLabel = GuiCtrlCreateLabel("Rathaus", 70, 90, 70, 20)
$RKosten = GuiCtrlCreateLabel("1", 160, 90, 30, 20)
$RZeit = GuiCtrlCreateLabel("1", 210, 90, 30, 20)
$RBauen = GuiCtrlCreateButton("Bauen", 260, 90, 70, 20)

$HLevel = GuiCtrlCreateLabel("0", 50, 130, 70, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$HLabel = GuiCtrlCreateLabel("Haus", 70, 130, 70, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$HKosten = GuiCtrlCreateLabel("5", 160, 130, 30, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$HZeit = GuiCtrlCreateLabel("5", 210, 130, 30, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$HBauen = GuiCtrlCreateButton("Bauen", 260, 130, 70, 20)
GUICtrlSetState(-1, $GUI_HIDE)

GuiSetState()

$Time = _TimeToTicks(@HOUR, @MIN, @SEC)
$TLabel = GuiCtrlCreateLabel(@HOUR & ":" & @MIN & ":" & @SEC, 150, 20)

While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $RBauen
            RBauen()
        Case $msg = $HBauen
            HBauen()
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
    
    If _TimeToTicks(@HOUR, @MIN, @SEC) = $Time+1*1000 Then
        GUICtrlSetData($Gold, GUICtrlRead($Gold)+1)
        $Time = _TimeToTicks(@HOUR, @MIN, @SEC)
        GUICtrlSetData($TLabel, @HOUR & ":" & @MIN & ":" & @SEC)
    EndIf
WEnd

Func RBauen()
    If GUICtrlRead($Gold) >= GUICtrlRead($RKosten) Then
        GUICtrlSetData($Gold, GUICtrlRead($Gold)-GUICtrlRead($RKosten))
        $EndTime = $Time+GUICtrlRead($RZeit)*1000
        $SaveRZeit = GUICtrlRead($RZeit)
        GUICtrlSetState($RBauen, $GUI_DISABLE)
        GUICtrlSetState($HBauen, $GUI_DISABLE)
        While 1
            If _TimeToTicks(@HOUR, @MIN, @SEC) = $EndTime Then
                GUICtrlSetData($RLevel, GUICtrlRead($RLevel)+1)
                If GUICtrlRead($RLevel) = 5 Then
                    GUICtrlSetState($HLevel, $GUI_SHOW)
                    GUICtrlSetState($HLabel, $GUI_SHOW)
                    GUICtrlSetState($HKosten, $GUI_SHOW)
                    GUICtrlSetState($HZeit, $GUI_SHOW)
                    GUICtrlSetState($HBauen, $GUI_SHOW)
                EndIf
                GUICtrlSetData($RKosten, GUICtrlRead($RKosten)+1)
                GUICtrlSetData($RZeit, $SaveRZeit+1)
                GUICtrlSetState($RBauen, $GUI_ENABLE)
                GUICtrlSetState($HBauen, $GUI_ENABLE)
                ExitLoop
            EndIf
            If _TimeToTicks(@HOUR, @MIN, @SEC) = $Time+1*1000 Then
                GUICtrlSetData($Gold, GUICtrlRead($Gold)+1)
                $Time = _TimeToTicks(@HOUR, @MIN, @SEC)
                GUICtrlSetData($TLabel, @HOUR & ":" & @MIN & ":" & @SEC)
                GUICtrlSetData($RZeit, GUICtrlRead($RZeit)-1)
            EndIf
            If GUIGetMsg() = $GUI_EVENT_CLOSE Then
                Exit
            EndIf
        WEnd
    EndIf
EndFunc

Func HBauen()
        If GUICtrlRead($Gold) >= GUICtrlRead($HKosten) Then
        GUICtrlSetData($Gold, GUICtrlRead($Gold)-GUICtrlRead($HKosten))
        $EndTime = $Time+GUICtrlRead($HZeit)*1000
        $SaveHZeit = GUICtrlRead($HZeit)
        GUICtrlSetState($RBauen, $GUI_DISABLE)
        GUICtrlSetState($HBauen, $GUI_DISABLE)
        While 1
            If _TimeToTicks(@HOUR, @MIN, @SEC) = $EndTime Then
                GUICtrlSetData($HLevel, GUICtrlRead($HLevel)+1)
                GUICtrlSetData($HKosten, GUICtrlRead($HKosten)+1)
                GUICtrlSetData($HZeit, $SaveHZeit+1)
                GUICtrlSetState($RBauen, $GUI_ENABLE)
                GUICtrlSetState($HBauen, $GUI_ENABLE)
                ExitLoop
            EndIf
            If _TimeToTicks(@HOUR, @MIN, @SEC) = $Time+1*1000 Then
                GUICtrlSetData($Gold, GUICtrlRead($Gold)+1)
                $Time = _TimeToTicks(@HOUR, @MIN, @SEC)
                GUICtrlSetData($TLabel, @HOUR & ":" & @MIN & ":" & @SEC)
                GUICtrlSetData($HZeit, GUICtrlRead($HZeit)-1)
            EndIf
            If GUIGetMsg() = $GUI_EVENT_CLOSE Then
                Exit
            EndIf
        WEnd
    EndIf
EndFunc

Share this post


Link to post
Share on other sites



Hugh, I haven't found the bug yet, but I wrote it new with Arrays, a better Style and more carefull and now it works...

;Name: Bauscript.au3
;Author: Lord_Doominik
;Status: In Progress (100%)
;Version: 1.0

#include <GUIConstants.au3>
#include <Date.au3>

;Variablen Deklaration
$Zeit = _TimeToTicks(@HOUR, @MIN, @SEC)
$Gold = 0

$RLevel = IniRead("Gebäude.crs", "Rathaus", "Level", "")
$RMaxLevel = IniRead("Gebäude.crs", "Rathaus", "MaxLevel", "")
$RKosten = StringSplit(IniRead("Gebäude.crs", "Rathaus", "Kosten", ""), ",")
$RBauzeit = StringSplit(IniRead("Gebäude.crs", "Rathaus", "Bauzeit", ""), ",")
$REinkommen = StringSplit(IniRead("Gebäude.crs", "Rathaus", "Einkommen", ""), ",")

$HLevel = IniRead("Gebäude.crs", "Haus", "Level", "")
$HMaxLevel = IniRead("Gebäude.crs", "Haus", "MaxLevel", "")
$HKosten = StringSplit(IniRead("Gebäude.crs", "Haus", "Kosten", ""), ",")
$HBauzeit = StringSplit(IniRead("Gebäude.crs", "Haus", "Bauzeit", ""), ",")
$HVorraussetzung = IniRead("Gebäude.crs", "Haus", "Vorraussetzung", "")

GUICreate("MyGUI", 392, 323,(@DesktopWidth-392)/2, (@DesktopHeight-323)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$ZAnzeige = GUICtrlCreateLabel(_NowTime(), 150, 20)

GUICtrlCreateLabel("Gold:", 70, 20, 30, 20)
$GAnzeige = GUICtrlCreateLabel($Gold, 100, 20, 90, 20)

GUICtrlCreateLabel("Kosten", 150, 60, 50, 20)
GUICtrlCreateLabel("Bauzeit", 200, 60, 50, 20)

$RLevelAnzeige = GUICtrlCreateLabel($RLevel, 50, 90, 70, 20)
GUICtrlCreateLabel("Rathaus", 70, 90, 70, 20)
$RKostenAnzeige = GUICtrlCreateLabel($RKosten[$RLevel], 160, 90, 30, 20)
$RBauzeitAnzeige = GUICtrlCreateLabel($RBauzeit[$RLevel], 210, 90, 30, 20)
$RBauen = GUICtrlCreateButton("Bauen", 260, 90, 70, 20)

$HLevelAnzeige = GUICtrlCreateLabel($HLevel, 50, 130, 70, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$HLabel = GUICtrlCreateLabel("Haus", 70, 130, 70, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$HKostenAnzeige = GUICtrlCreateLabel($HKosten[$HLevel+1], 160, 130, 30, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$HBauzeitAnzeige = GUICtrlCreateLabel($HBauzeit[$HLevel+1], 210, 130, 30, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$HBauen = GUICtrlCreateButton("Bauen", 260, 130, 70, 20)
GUICtrlSetState(-1, $GUI_HIDE)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $RBauen
            RBauen()
        Case $msg = $HBauen
            HBauen()
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
    
    If _TimeToTicks(@HOUR, @MIN, @SEC) = $Zeit+1*1000 Then
        $Zeit = _TimeToTicks(@HOUR, @MIN, @SEC)
        GUICtrlSetData($ZAnzeige, _NowTime())
        $Gold = $Gold + $REinkommen[$RLevel]
        GUICtrlSetData($GAnzeige, $Gold)
    EndIf
WEnd

Func RBauen()
    If $Gold >= $RKosten[$RLevel] Then
        $Gold = $Gold-$RKosten[$RLevel]
        GUICtrlSetData($GAnzeige, $Gold)
        $Endzeit = $Zeit+$RBauzeit[$RLevel]*1000
        
        GUICtrlSetState($RBauen, $GUI_DISABLE)
        GUICtrlSetState($HBauen, $GUI_DISABLE)
        
        While 1
            If _TimeToTicks(@HOUR, @MIN, @SEC) = $Zeit+1*1000 Then
                $Zeit = _TimeToTicks(@HOUR, @MIN, @SEC)
                GUICtrlSetData($ZAnzeige, _NowTime())
                GUICtrlSetData($RBauzeitAnzeige, GUICtrlRead($RBauzeitAnzeige)-1)
                $Gold = $Gold + $REinkommen[$RLevel]
                GUICtrlSetData($GAnzeige, $Gold)
            EndIf
            
            If _TimeToTicks(@HOUR, @MIN, @SEC) = $Endzeit Then
                $RLevel = $RLevel+1
                GUICtrlSetData($RLevelAnzeige, $RLevel)
                GUICtrlSetData($RKostenAnzeige, $RKosten[$RLevel])
                GUICtrlSetData($RBauzeitAnzeige, $RBauzeit[$RLevel])
                
                If $RLevel = $HVorraussetzung Then
                    GUICtrlSetState($HLevelAnzeige, $GUI_SHOW)
                    GUICtrlSetState($HLabel, $GUI_SHOW)
                    GUICtrlSetState($HKostenAnzeige, $GUI_SHOW)
                    GUICtrlSetState($HBauzeitAnzeige, $GUI_SHOW)
                    GUICtrlSetState($HBauen, $GUI_SHOW)
                EndIf
                
                GUICtrlSetState($RBauen, $GUI_ENABLE)
                GUICtrlSetState($HBauen, $GUI_ENABLE)
                
                If $RLevel = $RMaxLevel Then
                    GUICtrlSetState($RKostenAnzeige, $GUI_HIDE)
                    GUICtrlSetState($RBauzeitAnzeige, $GUI_HIDE)
                    GUICtrlSetState($RBauen, $GUI_HIDE)
                EndIf
                ExitLoop
            EndIf
        WEnd
    EndIf
EndFunc

Func HBauen()
    If $Gold >= $HKosten[$HLevel+1] Then
        $Gold = $Gold-$HKosten[$HLevel+1]
        GUICtrlSetData($GAnzeige, $Gold)
        $Endzeit = $Zeit+$HBauzeit[$HLevel+1]*1000
        
        GUICtrlSetState($RBauen, $GUI_DISABLE)
        GUICtrlSetState($HBauen, $GUI_DISABLE)
        
        While 1
            If _TimeToTicks(@HOUR, @MIN, @SEC) = $Zeit+1*1000 Then
                $Zeit = _TimeToTicks(@HOUR, @MIN, @SEC)
                GUICtrlSetData($ZAnzeige, _NowTime())
                GUICtrlSetData($HBauzeitAnzeige, GUICtrlRead($HBauzeitAnzeige)-1)
                $Gold = $Gold + $REinkommen[$RLevel]
                GUICtrlSetData($GAnzeige, $Gold)
            EndIf
            
            If _TimeToTicks(@HOUR, @MIN, @SEC) = $Endzeit Then
                $HLevel = $HLevel+1
                GUICtrlSetData($HLevelAnzeige, $HLevel)
                GUICtrlSetData($HKostenAnzeige, $HKosten[$HLevel+1])
                GUICtrlSetData($HBauzeitAnzeige, $HBauzeit[$HLevel+1])
                
                GUICtrlSetState($RBauen, $GUI_ENABLE)
                GUICtrlSetState($HBauen, $GUI_ENABLE)
                
                If $HLevel = $HMaxLevel Then
                    GUICtrlSetState($HKostenAnzeige, $GUI_HIDE)
                    GUICtrlSetState($HBauzeitAnzeige, $GUI_HIDE)
                    GUICtrlSetState($HBauen, $GUI_HIDE)
                EndIf
                ExitLoop
            EndIf
        WEnd
    EndIf
EndFunc

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