none
multi-button problem can anyone help RRS feed

  • Question

  • i hve problem with controls.buttonclicked

    when i press the button it doesnt work nothng happens even if i said that it should clear after pressing the button

    i looked at the button i used before but i couldnt find anything missing besides controls.buttonclicked

    and it says that there is no property buttonclicked in controls but i used it before and it worked

    here is the program:

    GraphicsWindow.Show()

    GraphicsWindow.Title="homework program-testB"

    GraphicsWindow.BackgroundColor="black"

    a=Controls.AddButton("Start the B-IQ 0.0.1",25,25)

    Controls.ButtonClicked= asub

    Sub asub

    b = Controls.LastClickedButton

    if b = a Then

    GraphicsWindow.Clear()

    Shapes.AddText("find the blue")

    GraphicsWindow.BrushColor="Red"

    GraphicsWindow.FillRectangle(10,50,50,20)

    GraphicsWindow.BrushColor="Cyan"

    GraphicsWindow.FillRectangle(70,50,50,20)

    EndIf

    EndSub

    GraphicsWindow.MouseDown=s

    Sub s

    x = GraphicsWindow.MouseX

    y = GraphicsWindow.MouseY

    If(x > 20 and x < 75 And y > 0 And y < 50)Then

      GraphicsWindow.Clear()

      GraphicsWindow.BrushColor="yellow"

      Shapes.AddText("click me to go to the next level")

     GraphicsWindow.BrushColor="black"

    d=Controls.AddButton("HERE! ME ME !!",50,50)

    e= Controls.LastClickedButton

    If (e = d) then

      GraphicsWindow.Clear()

      EndIf

    EndIf

    EndSub

    can you help me to do this :)

    Sunday, March 22, 2015 11:00 PM

Answers

  • Hello, Berkin01Arslan.

    I added two lines to show green rectangle.  Click on the green.

    GraphicsWindow.Show()
    GraphicsWindow.Title="homework program-testB"
    GraphicsWindow.BackgroundColor="black"
    a=Controls.AddButton("Start the B-IQ 0.0.1",25,25)
    Controls.ButtonClicked= asub
    Sub asub
      b = Controls.LastClickedButton
      if b = a Then
        GraphicsWindow.Clear()
        Shapes.AddText("find the blue")
        GraphicsWindow.BrushColor="Red"
        GraphicsWindow.FillRectangle(10,50,50,20)
        GraphicsWindow.BrushColor="Cyan"
        GraphicsWindow.FillRectangle(70,50,50,20)
        GraphicsWindow.BrushColor="Green"         ' added
        GraphicsWindow.FillRectangle(20,0,55,50)  ' added
      EndIf
    EndSub
    GraphicsWindow.MouseDown=s
    Sub s
      x = GraphicsWindow.MouseX
      y = GraphicsWindow.MouseY
      If(x > 20 and x < 75 And y > 0 And y < 50)Then
        GraphicsWindow.Clear()
        GraphicsWindow.BrushColor="yellow"
        Shapes.AddText("click me to go to the next level")
        GraphicsWindow.BrushColor="black"
        d=Controls.AddButton("HERE! ME ME !!",50,50)
        e= Controls.LastClickedButton
        If (e = d) then
          GraphicsWindow.Clear()
        EndIf
      EndIf
    EndSub


    Nonki Takahashi


    Monday, March 23, 2015 12:51 AM
    Moderator
  • Hello, Berkin01Arslan.

    As a tip:

    Do not put main program commands between subroutines. It is best to put all subroutines at the end, after all of the main program.

    In your program it is easy to see that you have the MouseDown between the two subs, but in longer programs, someone reading your program can overlook that line in that position.


    Jan [ WhTurner ] The Netherlands

    Monday, March 23, 2015 10:06 AM
    Answerer

All replies

  • Hello, Berkin01Arslan.

    I added two lines to show green rectangle.  Click on the green.

    GraphicsWindow.Show()
    GraphicsWindow.Title="homework program-testB"
    GraphicsWindow.BackgroundColor="black"
    a=Controls.AddButton("Start the B-IQ 0.0.1",25,25)
    Controls.ButtonClicked= asub
    Sub asub
      b = Controls.LastClickedButton
      if b = a Then
        GraphicsWindow.Clear()
        Shapes.AddText("find the blue")
        GraphicsWindow.BrushColor="Red"
        GraphicsWindow.FillRectangle(10,50,50,20)
        GraphicsWindow.BrushColor="Cyan"
        GraphicsWindow.FillRectangle(70,50,50,20)
        GraphicsWindow.BrushColor="Green"         ' added
        GraphicsWindow.FillRectangle(20,0,55,50)  ' added
      EndIf
    EndSub
    GraphicsWindow.MouseDown=s
    Sub s
      x = GraphicsWindow.MouseX
      y = GraphicsWindow.MouseY
      If(x > 20 and x < 75 And y > 0 And y < 50)Then
        GraphicsWindow.Clear()
        GraphicsWindow.BrushColor="yellow"
        Shapes.AddText("click me to go to the next level")
        GraphicsWindow.BrushColor="black"
        d=Controls.AddButton("HERE! ME ME !!",50,50)
        e= Controls.LastClickedButton
        If (e = d) then
          GraphicsWindow.Clear()
        EndIf
      EndIf
    EndSub


    Nonki Takahashi


    Monday, March 23, 2015 12:51 AM
    Moderator
  • Hello, Berkin01Arslan.

    As a tip:

    Do not put main program commands between subroutines. It is best to put all subroutines at the end, after all of the main program.

    In your program it is easy to see that you have the MouseDown between the two subs, but in longer programs, someone reading your program can overlook that line in that position.


    Jan [ WhTurner ] The Netherlands

    Monday, March 23, 2015 10:06 AM
    Answerer
  • thank you alot but this didnt work either do you think that my small basic can have a problem ?
    Friday, April 24, 2015 7:42 AM
  • thank you for your advise
    Friday, April 24, 2015 7:43 AM
  • Hello, Berkin01Arslan

    Program #: SXZ409

    Here is a generic sample that demonstrates the mouse event. It provides a means to more accurately track user input. I also provided this sample to see if the problems with small basic persist. On occasion, copying and pasting code directly from the forum as oppose to using a code number (as shown above in my reply) may copy text from the html page as well as the code. As a result, the IDE doesn't recognize the program. Could you specific, if the problem persist, what exactly isn't working. Does the program simply not run? If it does work and you have any questions regarding the provided code let me know.

    Friday, April 24, 2015 8:05 PM
  • Hi Berkin01Arslan,

    try it with some corrections:
    - query xy of the blue button
    - put the button-event in the right sub

    GraphicsWindow.Show()
    GraphicsWindow.Title="homework program-testB"
    GraphicsWindow.BackgroundColor="black"
    a=Controls.AddButton("Start the B-IQ 0.0.1",25,25)
    Controls.ButtonClicked= asub
    GraphicsWindow.MouseDown=s
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub asub
    b = Controls.LastClickedButton
    if b = a Then
      GraphicsWindow.Clear()
      Shapes.AddText("find the blue")
      GraphicsWindow.BrushColor="Red"
      GraphicsWindow.FillRectangle(10,50,50,20)
      GraphicsWindow.BrushColor="Cyan"
      GraphicsWindow.FillRectangle(70,50,50,20)
    EndIf
    If b = d then
      GraphicsWindow.Clear()
    EndIf
    EndSub
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub s
    x = GraphicsWindow.MouseX
    y = GraphicsWindow.MouseY
    If(x > 70 and x < 120 And y > 50 And y < 70)Then  'check the correct bounds
      GraphicsWindow.Clear()
      GraphicsWindow.BrushColor="yellow"
      Shapes.AddText("click me to go to the next level")
      GraphicsWindow.BrushColor="black"
    d=Controls.AddButton("HERE! ME ME !!",50,50)
    EndIf
    EndSub

    You can make with "Remove" Buttons a nice game like whac a mole

    Friday, April 24, 2015 8:30 PM