Jump to content

I'm really confused...


Recommended Posts

I've been working on a code that I hope is going to be really cool and fun to play around with but I'm running into some errors. I've fixed 99.99% of the problems because people have helped me in the past and I learned from it and I managed to use that information to help me fix errors with no extra help.

But there is one problem that's had me stuck for about 2-3 hours now (Average time I give something before I get help).

The code I'm working on is 700+ lines long (Because I don't know all the sneaky shortcuts) so I'm just going to post a smaller version that is the same exact thing just with a lot less lines.

#include <GUIConstantsEx.au3>
 Local $testgui, $button1,$result,$dis1,$dis2,$dos1,$dos2,$bill,$amount
 Call("testgui")
 while 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
    Case $testgui
       Switch $msg[0]
       Case $button1
          $randomresult = Random(1,2,1)
          GUICtrlSetData($result,$randomresult)
          If $dos1 = 1 Then
    If $randomresult = 1 Then
       $bill = $bill - 5
       GUICtrlSetData($amount,"$"&$bill)
    EndIf
 EndIf
 If $dos2 = 2 Then
    If $randomresult = 2 Then
       $bill = $bill + 5
       GUICtrlSetData($amount,"$"&$bill)
    EndIf
    EndIf
       Case $dis1
          GUICtrlSetState($dis1,$GUI_DISABLE)
          GUICtrlSetState($dis2,$GUI_ENABLE)
          $dos1 = 1
       Case $dis2
          GUICtrlSetState($dis2,$GUI_DISABLE)
          GUICtrlSetState($dis1,$GUI_ENABLE)
          $dos2 = 2
       Case -3
          Exit
       EndSwitch
    EndSwitch
    WEnd
 Func testgui()
 $testgui = GUICreate("",200,200)
 $button1 = GUICtrlCreateButton("Random",0,0,100,30)
 $result = GUICtrlCreateLabel("",150,0,100,30)
 $bill = "100"
 $amount = GUICtrlCreateLabel("$"&$bill,0,175,100,30)
 GUICtrlSetFont($result,15,700,2,"Minion Pro")
 $dis1 = GUICtrlCreateButton("1",0,50,20,20)
 $dis2 = GUICtrlCreateButton("2",0,100,20,20)
 GUISetState()
 EndFunc

The objective is to press the button to choose an option and I have it set the disable the button to make it look like you clicked it so you don't forget it. But when you click "1" then click "2" it does both where it adds and subtracts 5 on 1 & 2 (Depending on the random result).

Another problem with my longer code is it all works fine (It doesn't do what this code does, not sure why) it just calls the wrong function even though the variables and if/thens are completely different and I can't figure out if it is just somewhere else.

Here's the download for my longer code if you want to see it.

Game making.au3

Link to comment
Share on other sites

You have set $dos1 to 1 when the player picks that number, then also set $dos2 to 2 if the user chooses that number, but you didn't reset $dos1, so he is indeed choosing both.  Also, you were taking money from the player when they bet on 1 and were correct.

This is your code, just modified to work as is.

#include <GUIConstantsEx.au3>
Local $testgui, $button1, $result, $dis1, $dis2, $dos, $bill, $amount
Call("testgui")
While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $testgui
            Switch $msg[0]
                Case $button1
                    $randomresult = Random(1, 2, 1)
                    GUICtrlSetData($result, $randomresult)
                    ;Just using 1 variable to track the selection ($dos)
                    If $dos = 1 Then
                        If $randomresult = 1 Then
                            ;I should get paid if I am correct.
                            $bill = $bill + 5
                        Else
                            ;Added an else statement for if I lose
                            $bill = $bill - 5
                        EndIf
                        ;Moving the SetData for $amount to after I win or lose
                        GUICtrlSetData($amount, "$" & $bill)
                    EndIf
                    ;Just using 1 variable to track the selection ($dos)
                    If $dos = 2 Then
                        If $randomresult = 2 Then
                            $bill = $bill + 5
                        Else
                            ;Added an else statement for if I lose
                            $bill = $bill - 5
                        EndIf
                        ;Moving the SetData for $amount to after I win or lose
                        GUICtrlSetData($amount, "$" & $bill)
                    EndIf
                Case $dis1
                    GUICtrlSetState($dis1, $GUI_DISABLE)
                    GUICtrlSetState($dis2, $GUI_ENABLE)
                    ;Just using 1 variable to track the selection ($dos)
                    $dos = 1
                Case $dis2
                    GUICtrlSetState($dis2, $GUI_DISABLE)
                    GUICtrlSetState($dis1, $GUI_ENABLE)
                    ;Just using 1 variable to track the selection ($dos)
                    $dos = 2
                Case -3
                    Exit
            EndSwitch
    EndSwitch
WEnd
Func testgui()
    $testgui = GUICreate("", 200, 200)
    $button1 = GUICtrlCreateButton("Random", 0, 0, 100, 30)
    $result = GUICtrlCreateLabel("", 150, 0, 100, 30)
    $bill = "100"
    $amount = GUICtrlCreateLabel("$" & $bill, 0, 175, 100, 30)
    GUICtrlSetFont($result, 15, 700, 2, "Minion Pro")
    $dis1 = GUICtrlCreateButton("1", 0, 50, 20, 20)
    $dis2 = GUICtrlCreateButton("2", 0, 100, 20, 20)
    GUISetState()
EndFunc   ;==>testgui
Link to comment
Share on other sites

  • Moderators

Could you also think about giving your posts meaningful titles in the future? Everyone on this forum is confused about something, or they wouldn't be seeking help ;)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Sorry about the title JLogan I wasn't sure what to call it and I was going to bed just wanted to post it real quick.

DW1, The code you posted is doing exactly what I needed it to do so thank you for that. Hopefully I can remember the minor changes so I won't have to bother anyone again.

Thanks  :thumbsup:

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...