none
plz help with this slot machine program

    Question

  • basically it alternates between love and hate option and if you click the buttom while in love you win and in hate you lose

    the problem is that many times i hit the buttom it does nothing

    any help plz?

    GraphicsWindow.Show()
    re:
    a=Controls.AddButton("xxxxxxxxxxxxx",111,111)
    GraphicsWindow.DrawText(222,222,"gains"+bob)
    GraphicsWindow.DrawText(433,333,"HATE")
    For i=1 To 100000
    Controls.ButtonClicked=lose
    endfor
    GraphicsWindow.Clear()


    a=Controls.AddButton("xxxxxxxxxxxxx",111,111)
    GraphicsWindow.DrawText(222,222,"gains"+bob)
    GraphicsWindow.DrawText(333,333,"LOVE")
    For i=1 To 100000
    Controls.ButtonClicked=win
    endfor
    GraphicsWindow.Clear()
    Goto re

    Sub lose
      bob=bob-1
    EndSub
    Sub win
      bob=bob+1
      EndSub

    Wednesday, March 15, 2017 6:49 PM

Answers

  • Check out https://social.technet.microsoft.com/wiki/contents/articles/15060.small-basic-event-basics.aspx

    1. Only create events once if possible
    2. Try not to use GraphicsWindow.Clear() - can cause flicker and removes all controls - perhaps use Textbox or other control in place of drawing (see https://social.technet.microsoft.com/wiki/contents/articles/15059.small-basic-graphicswindow-basics.aspx).  I use a rectangle same colour as background to partially clear section of GW - not very elegant but better than repeated Clear.
    3. Try not to use GoTo

    Maybe start like this?

    a=Controls.AddButton("xxxxxxxxxxxxx",111,111)
    Controls.ButtonClicked=OnButtonClicked
    
    state = "LOVE"
    Timer.Interval = 1000
    Timer.Tick = OnTick
    
    Sub OnTick
      If (state = "LOVE") Then
        state = "HATE"
      Else
        state = "LOVE"
      EndIf
      Update()
    EndSub
    
    Sub OnButtonClicked
      If (state = "LOVE") Then
        bob=bob+1
      Else
        bob=bob-1
      EndIf
      Update()
    EndSub
    
    Sub Update
      lastBursh = GraphicsWindow.BrushColor
      GraphicsWindow.BrushColor = GraphicsWindow.BackgroundColor
      GraphicsWindow.FillRectangle(0,200,1000,1000)
      GraphicsWindow.BrushColor = lastBursh
      If (state = "LOVE") Then
        GraphicsWindow.DrawText(333,333,"LOVE")
      Else
        GraphicsWindow.DrawText(433,333,"HATE")
      EndIf
      GraphicsWindow.DrawText(222,222,"gains "+bob)
    EndSub
    

    • Marked as answer by antonio glez Wednesday, March 15, 2017 8:05 PM
    Wednesday, March 15, 2017 7:54 PM
    Moderator

All replies

  • The Controls.ButtonClicked is a flag wich is set when that line is executed. You only call that once, thus NOT in a For-loop.

    You have to rethink your logic.


    Jan [ WhTurner ] The Netherlands

    Wednesday, March 15, 2017 7:01 PM
    Answerer
  • i tried this but neither works:


    GraphicsWindow.Show()
    re:
    a=Controls.AddButton("xxxxxxxxxxxxx",111,111)
    GraphicsWindow.DrawText(222,222,"gains"+bob)
    GraphicsWindow.DrawText(433,333,"HATE")
    For i=1 To 50000
      If Controls.LastClickedButton=a Then
        bob=bob-1
        Goto skip1
        EndIf
    endfor
    skip1:
    GraphicsWindow.Clear()

    a=Controls.AddButton("xxxxxxxxxxxxx",111,111)
    GraphicsWindow.DrawText(222,222,"gains"+bob)
    GraphicsWindow.DrawText(333,333,"LOVE")
    For i=1 To 50000
      If Controls.LastClickedButton=a Then
        bob=bob+1
        Goto skip2
        EndIf
    endfor
    skip2:
    GraphicsWindow.Clear()
    Goto re

    Sub lose
      bob=bob-1
    EndSub
    Sub win
      bob=bob+1
      EndSub

    Wednesday, March 15, 2017 7:51 PM
  • Check out https://social.technet.microsoft.com/wiki/contents/articles/15060.small-basic-event-basics.aspx

    1. Only create events once if possible
    2. Try not to use GraphicsWindow.Clear() - can cause flicker and removes all controls - perhaps use Textbox or other control in place of drawing (see https://social.technet.microsoft.com/wiki/contents/articles/15059.small-basic-graphicswindow-basics.aspx).  I use a rectangle same colour as background to partially clear section of GW - not very elegant but better than repeated Clear.
    3. Try not to use GoTo

    Maybe start like this?

    a=Controls.AddButton("xxxxxxxxxxxxx",111,111)
    Controls.ButtonClicked=OnButtonClicked
    
    state = "LOVE"
    Timer.Interval = 1000
    Timer.Tick = OnTick
    
    Sub OnTick
      If (state = "LOVE") Then
        state = "HATE"
      Else
        state = "LOVE"
      EndIf
      Update()
    EndSub
    
    Sub OnButtonClicked
      If (state = "LOVE") Then
        bob=bob+1
      Else
        bob=bob-1
      EndIf
      Update()
    EndSub
    
    Sub Update
      lastBursh = GraphicsWindow.BrushColor
      GraphicsWindow.BrushColor = GraphicsWindow.BackgroundColor
      GraphicsWindow.FillRectangle(0,200,1000,1000)
      GraphicsWindow.BrushColor = lastBursh
      If (state = "LOVE") Then
        GraphicsWindow.DrawText(333,333,"LOVE")
      Else
        GraphicsWindow.DrawText(433,333,"HATE")
      EndIf
      GraphicsWindow.DrawText(222,222,"gains "+bob)
    EndSub
    

    • Marked as answer by antonio glez Wednesday, March 15, 2017 8:05 PM
    Wednesday, March 15, 2017 7:54 PM
    Moderator
  • thanks a lot for your help

    i tweaked it a bit adding it sound and a bit of colour, here the final slot machine trainer which is quite similar to the doubling prize of real fruit machines :)

    slot

    Wednesday, March 15, 2017 9:08 PM