locked
WAIT!!! RRS feed

  • Question

  • Hello! I am VERY new to the whole programming thing and there is a problem I can't solve.

    I am writing a program in Small Basic, and I need the Graphics Window to wait for user input. The user input the program requires is clicking one of three buttons placed on the window. Does anyone have any suggestions on how to solve this?

    Tuesday, July 19, 2016 10:17 AM

Answers

  • Hi Boris !

    try this:

    GraphicsWindow.BackgroundColor="Yellow"
     GraphicsWindow.DrawText(250,150,"Select an action")
     Rock=Controls.AddButton("Rock",175,250)
     Paper=Controls.AddButton("Paper",275,250)
     Scissors=Controls.AddButton("Scissors",375,250)
     Computer=Math.GetRandomNumber(3)
    Controls.ButtonClicked=ButtonWasClicked

    Sub ButtonWasClicked
     
      button = Controls.LastClickedButton
     
     'Rock results
     If button = rock  And Computer=1 Then
       tie()
     ElseIf button = rock  And Computer=2 then
       lose()
     ElseIf button = rock  And Computer=3 then
       win()
     EndIf
     
     If button = paper  And Computer=2 Then
       tie()
     ElseIf button = paper  And Computer=1 then
       lose()
     ElseIf button = paper  And Computer=3 then
       win()
     EndIf
     
      If button = Scissors  And Computer=3 Then
       tie()
     ElseIf button = Scissors and Computer=1 then
       lose()
     ElseIf button = Scissors and Computer=2 then
       win()
     EndIf
     
     
    EndSub
      
      
      
     sub win
     GraphicsWindow.DrawBoundText(10,10,300,"You Win !")
    EndSub
    sub lose
      GraphicsWindow.DrawBoundText(10,10,300,"You Lose !")
    EndSub
    sub tie
      GraphicsWindow.DrawBoundText(10,10,300,"It's a Tie !")
     endsub

    • Proposed as answer by Nonki Takahashi Friday, July 29, 2016 4:26 AM
    • Marked as answer by litdev Saturday, August 6, 2016 11:21 AM
    Thursday, July 21, 2016 2:09 PM
    Answerer

All replies

  • Hi ! welcome to the Small Basic forum.

    try to post what you've done so far on the forum, to have a more precise view of what you want to do.

    Do you want to use Boxes or graphic.windows.textbox ?

    do you will use the mouse or the keyboard for input the answer ?

     For Buttons event here is wonderful example wrote by litdev in this thread:  Button Events

    button1 = Controls.AddButton("Button 1",50,50)
     button2 = Controls.AddButton("Button 2",50,100)
     Controls.ButtonClicked = OnButtonClicked
     Sub OnButtonClicked
       button = Controls.LastClickedButton
       If (button = button1) Then
         GraphicsWindow.ShowMessage("Button 1 pressed", "Information")
       ElseIf (button = button2) Then
         GraphicsWindow.ShowMessage("Button 2 pressed", "Information")
       EndIf
     EndSub


    Tuesday, July 19, 2016 1:20 PM
    Answerer
  • Thanks for the response. However, this is already written in the code. My problem is that the program (the graphics window is being used) doesn't wait for one of the buttons to be clicked using a mouse. It instead displays goes directly to the message that will be displayed when the program ends.
    Wednesday, July 20, 2016 11:42 AM
  • Can you publish it so that we can see the code?

    Ed Price, Azure Development Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Thursday, July 21, 2016 7:33 AM
  • GraphicsWindow.BackgroundColor="Yellow"
    GraphicsWindow.DrawText(250,150,"Select an action")
    Rock=Controls.AddButton("Rock",175,250)
    Paper=Controls.AddButton("Paper",275,250)
    Scissors=Controls.AddButton("Scissors",375,250)
    Computer=Math.GetRandomNumber(3)

    Controls.ButtonClicked=ButtonWasClicked
    Sub ButtonWasClicked
    'Rock results 
    If Controls.LastClickedButton=Rock And Computer=1 Then
      Goto tie
    ElseIf Controls.LastClickedButton=Rock and Computer=2 then
      Goto lose
    ElseIf Controls.LastClickedButton=Rock and Computer=3 then
      Goto win
      'Paper results
      ElseIf Controls.LastClickedButton=Paper And Computer=1 Then
      Goto win
    ElseIf Controls.LastClickedButton=Paper and Computer=2 then
      Goto tie
    ElseIf Controls.LastClickedButton=Paper and Computer=3 then
      Goto lose
      'Scissors results
      Elseif Controls.LastClickedButton=Scissors And Computer=1 Then
      Goto lose
    ElseIf Controls.LastClickedButton=Scissors and Computer=2 then
      Goto win
    ElseIf Controls.LastClickedButton=Scissors and Computer=3 then
      Goto tie
      EndIf
    EndSub

    win:
    TextWindow.Show()
    TextWindow.WriteLine("You win!")
    Goto end
    lose:
    TextWindow.Show()
    TextWindow.WriteLine("You Lose! :(")
    Goto end
    tie:
    TextWindow.Show()
    TextWindow.WriteLine("It's a tie!")
    Goto end

    end:
    Program.Delay(5000)
    Program.End()

    This is everything I have written so far. Feel free to change anything.

    Thursday, July 21, 2016 12:37 PM
  • Hi Boris !

    try this:

    GraphicsWindow.BackgroundColor="Yellow"
     GraphicsWindow.DrawText(250,150,"Select an action")
     Rock=Controls.AddButton("Rock",175,250)
     Paper=Controls.AddButton("Paper",275,250)
     Scissors=Controls.AddButton("Scissors",375,250)
     Computer=Math.GetRandomNumber(3)
    Controls.ButtonClicked=ButtonWasClicked

    Sub ButtonWasClicked
     
      button = Controls.LastClickedButton
     
     'Rock results
     If button = rock  And Computer=1 Then
       tie()
     ElseIf button = rock  And Computer=2 then
       lose()
     ElseIf button = rock  And Computer=3 then
       win()
     EndIf
     
     If button = paper  And Computer=2 Then
       tie()
     ElseIf button = paper  And Computer=1 then
       lose()
     ElseIf button = paper  And Computer=3 then
       win()
     EndIf
     
      If button = Scissors  And Computer=3 Then
       tie()
     ElseIf button = Scissors and Computer=1 then
       lose()
     ElseIf button = Scissors and Computer=2 then
       win()
     EndIf
     
     
    EndSub
      
      
      
     sub win
     GraphicsWindow.DrawBoundText(10,10,300,"You Win !")
    EndSub
    sub lose
      GraphicsWindow.DrawBoundText(10,10,300,"You Lose !")
    EndSub
    sub tie
      GraphicsWindow.DrawBoundText(10,10,300,"It's a Tie !")
     endsub

    • Proposed as answer by Nonki Takahashi Friday, July 29, 2016 4:26 AM
    • Marked as answer by litdev Saturday, August 6, 2016 11:21 AM
    Thursday, July 21, 2016 2:09 PM
    Answerer
  • Thanks. The program works as intended. By the way, I can't find my Small Basic install directory. My desktop shortcut leads me to another shortcut.

    Friday, July 22, 2016 9:04 AM
  • It should be

    C:\Program Files (x86)\Microsoft\Small Basic (on 64 bit)

    or

    C:\Program Files\Microsoft\Small Basic (on 32 bit)

    Sunday, July 24, 2016 11:47 AM