Sign in to follow this  
Followers 0
Jex

Strange problem about simple slot game

3 posts in this topic

#include <GUIConstants.au3>

Global $Input[4]

$Form = GUICreate("Slot", 210, 65, 255, 147)
$Input[1] = GUICtrlCreateInput(Random(1, 10, 1), 8, 8, 45, 45, $ES_CENTER)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Input[2] = GUICtrlCreateInput(Random(1, 10, 1), 56, 8, 45, 45, $ES_CENTER)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Input[3] = GUICtrlCreateInput(Random(1, 10, 1), 104, 8, 45, 45, $ES_CENTER)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Button = GUICtrlCreateButton("Spin", 152, 8, 45, 45, 0)
;$Input4 = GUICtrlCreateInput("Input4", 104, 56, 89, 21)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            $Spin = Spin()
            If $Spin[1] = $Spin[2] And $Spin[2] = $Spin[3] Then MsgBox("", "", "You won " & $Spin[1] * 10 & " point.")
    EndSwitch
WEnd

Func Spin()
    Local $Slot[4], $Cur[4]
    For $i = 1 To 3
        $Cur[$i] = GUICtrlRead($Input[$i])
    Next
    For $z = 1 To 75
        For $i = 1 To 3
            $Random = Random(1, ((80 - $z) / 3) / 5, 1)
            $Cur[$i] += $Random
            If $Cur[$i] > 10 Then $Cur[$i] = $Cur[$i] - 10
            TrayTip("", $z & "    " & $Cur[1] & " " & $Cur[2] & " " & $Cur[3], 1) ;Debug
            GUICtrlSetData($Input[$i], $Cur[$i])
        Next
        Sleep(($z / 4) * 10)
    Next
    Return $Cur
EndFunc   ;==>Spin

I'm added TrayTip for see what is going wrong. You can see after $z = 65, TrayTip not change.

I mean after $z = 65 in For Next loop. ( Line 35 to 44 )

I can't find what is wrong. I mean bug?

Share this post


Link to post
Share on other sites



#include <GUIConstants.au3>

Global $Input[4]

$Form = GUICreate("Slot", 210, 65, 255, 147)
$Input[1] = GUICtrlCreateInput(Random(1, 10, 1), 8, 8, 45, 45, $ES_CENTER)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Input[2] = GUICtrlCreateInput(Random(1, 10, 1), 56, 8, 45, 45, $ES_CENTER)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Input[3] = GUICtrlCreateInput(Random(1, 10, 1), 104, 8, 45, 45, $ES_CENTER)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Button = GUICtrlCreateButton("Spin", 152, 8, 45, 45, 0)
;$Input4 = GUICtrlCreateInput("Input4", 104, 56, 89, 21)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            $Spin = Spin()
            If $Spin[1] = $Spin[2] And $Spin[2] = $Spin[3] Then MsgBox("", "", "You won " & $Spin[1] * 10 & " point.")
    EndSwitch
WEnd

Func Spin()
    Local $Slot[4], $Cur[4]
    For $i = 1 To 3
        $Cur[$i] = GUICtrlRead($Input[$i])
    Next
    For $z = 1 To 75
        For $i = 1 To 3
            $Random = Random(1, ((80 - $z) / 3) / 5, 1)
            $Cur[$i] += $Random
            If $Cur[$i] > 10 Then $Cur[$i] = $Cur[$i] - 10
            TrayTip("", $z & "    " & $Cur[1] & " " & $Cur[2] & " " & $Cur[3], 1) ;Debug
            GUICtrlSetData($Input[$i], $Cur[$i])
        Next
        Sleep(($z / 4) * 10)
    Next
    Return $Cur
EndFunc   ;==>Spin

I'm added TrayTip for see what is going wrong. You can see after $z = 65, TrayTip not change.

I mean after $z = 65 in For Next loop. ( Line 35 to 44 )

I can't find what is wrong. I mean bug?

When you get to 65 the result of

(80 - 65)/3/5

is 1.

Random(1,1) returns 0


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

When you get to 65 the result of

(80 - 65)/3/5

is 1.

Random(1,1) returns 0

Thanks, i think Random(1, 1) return 1 but i'm false.

Working script :

#include <GUIConstants.au3>

Global $Input[4]

$Form = GUICreate("Slot", 210, 65, 255, 147)
$Input[1] = GUICtrlCreateInput(Random(1, 10, 1), 8, 8, 45, 45, $ES_CENTER)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Input[2] = GUICtrlCreateInput(Random(1, 10, 1), 56, 8, 45, 45, $ES_CENTER)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Input[3] = GUICtrlCreateInput(Random(1, 10, 1), 104, 8, 45, 45, $ES_CENTER)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Button = GUICtrlCreateButton("Spin", 152, 8, 45, 45, 0)
;$Input4 = GUICtrlCreateInput("Input4", 104, 56, 89, 21)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            $Spin = Spin()
            If $Spin[1] = $Spin[2] And $Spin[2] = $Spin[3] Then MsgBox("", "", "You won " & $Spin[1] * 10 & " point.")
    EndSwitch
WEnd

Func Spin()
    Local $Slot[4], $Cur[4]
    For $i = 1 To 3
        $Cur[$i] = GUICtrlRead($Input[$i])
    Next
    For $z = 1 To 50
        For $i = 1 To 3
            $Random = Random(1, ((70 - $z) / 3) / 5, 1)
            If $Random < 1 Then $Random = 1
            $Cur[$i] += $Random
            If $Cur[$i] > 10 Then $Cur[$i] = $Cur[$i] - 10
            GUICtrlSetData($Input[$i], $Cur[$i])
        Next
        Sleep(($z / 4) * 15)
    Next
    Return $Cur
EndFunc   ;==>Spin
Edited by Jex

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