locked
Not working... please fix code... RRS feed

  • Question

  • Hello. I want to make something like SimCity or something, but buttons doesn't work, while I click on one of this.

    Please fix it. Thanks.

    Money = 0
    button = Controls.AddButton("$$$", 400, 400)
    buttonlol = Controls.AddButton("Check out your money!", 360, 0)
    While ( Controls.LastClickedButton = button )

      Controls.ButtonClicked = lolo1

    endwhile

    while ( Controls.LastClickedButton = buttonlol )

      Controls.ButtonClicked = lolo2

    endwhile
    GraphicsWindow.BackgroundColor = "#DCDCDC"
    GraphicsWindow.Width = 500
    GraphicsWindow.Height = 500
    GraphicsWindow.CanResize = 0


    Sub lolo1
      Sound.Stop("link1") <------- link to the sound 1
      Controls.Move(button, Math.GetRandomNumber(400),Math.GetRandomNumber(400))
      Sound.Play("link1") <------- link to the sound 1
     GraphicsWindow.ShowMessage ( "Money Getted : " + Money + "$", "Your Money!")
      Money = Money + Math.GetRandomNumber ( 1250 )
    endsub

      Sub lolo2
        Sound.PlayChimes()
        GraphicsWindow.ShowMessage( "Money : " + Money + "$", "BANK")
        Sound.Stop("link1")  <------- link to the sound 1
        endsub

           
    Saturday, September 10, 2016 9:03 PM

Answers

  • Somehow like:

    Money = 0
    GraphicsWindow.BackgroundColor = "#DCDCDC"
    GraphicsWindow.CanResize = 0
    GraphicsWindow.Width = 500
    GraphicsWindow.Height = 500
    
    button = Controls.AddButton("$$$", 400,400)
    buttonlol = Controls.AddButton("Check out your money!", 360,0)
    
    
    Controls.ButtonClicked = OnButtonClicked
    
    ' EVENT
    Sub OnButtonClicked
      lastButton = Controls.LastClickedButton
      If lastButton = button Then
        lolo1()
      ElseIf lastButton = buttonlol Then
        lolo2()
      EndIf
    EndSub
    
    ' SUBs
    Sub lolo1
      'Sound.Stop("link1")
      Controls.Move(button, Math.GetRandomNumber(400), Math.GetRandomNumber(400))
      'Sound.Play("link1")
      GraphicsWindow.ShowMessage("Money Getted : " + Money + "$", "Your Money!")
      Money = Money + Math.GetRandomNumber(1250)
    EndSub
    
    Sub lolo2
      'Sound.PlayChimes()
      GraphicsWindow.ShowMessage( "Money : " + Money + "$", "BANK")
      'Sound.Stop("link1") 
    EndSub

    And a hint for free. You should read Curriculum: Lesson 3.4: Events and Interactivity, about How to work with events.

    Here's the whole curriculum: Small Basic Curriculum


    • Proposed as answer by litdev Sunday, September 11, 2016 9:04 PM
    • Marked as answer by WhTurner33Editor Thursday, September 29, 2016 11:25 AM
    Saturday, September 10, 2016 10:47 PM
    Answerer