Menu problem

Jiří Ferus 1 Reputation point
2022-12-07T16:36:32.65+00:00

I have this chunk of code and MenuButton don't work can you please help me?

'setup
Start:
GraphicsWindow.Clear()
GraphicsWindow.BrushColor="#2E4057"
GraphicsWindow.CanResize="false"
GraphicsWindow.Width=1500
GraphicsWindow.Height=700
GraphicsWindow.BackgroundColor="#FFFFE0"
GraphicsWindow.FontSize=100
GraphicsWindow.DrawText(135, 100, "Zeměpis Pololetní Práce")
GraphicsWindow.FontSize=20
GraphicsWindow.DrawText(5, 675, "version 1.0.2")
GraphicsWindow.FontSize=100
NumberOfWrongAnswers = 0
Controls.ButtonClicked=OnButtonClicked
'subroutiens
Sub DrawFinishBox
GraphicsWindow.Clear()
GraphicsWindow.FontSize=100
GraphicsWindow.DrawText(500, 200, "Vše správně")
GraphicsWindow.FontSize=80
GraphicsWindow.DrawText(300, 300, "Počet špatných odpovědí: " + NumberOfWrongAnswers)
GraphicsWindow.FontSize=100
question = 0
AllDoneButton = Controls.AddButton("Zpět", 510, 430)
EndSub
Sub DrawRightBox
GraphicsWindow.Clear()
GraphicsWindow.FontSize=100
GraphicsWindow.DrawText(500, 200, "Dobře")
NextButton = Controls.AddButton("Další", 510, 340)
EndSub
Sub DrawWrongBox
GraphicsWindow.Clear()
GraphicsWindow.FontSize=100
GraphicsWindow.DrawText(500, 200, "Špatně")
ZnovaButton = Controls.AddButton("Znova", 510, 340)
EndSub
Sub DrawQuestionBox
GraphicsWindow.Clear()
GraphicsWindow.FontSize=100
GraphicsWindow.DrawText(250, 100, "Odpověz na otázky")
GraphicsWindow.FontSize=20
MenuButton = Controls.AddButton("Menu", 1, 1)
GraphicsWindow.FontSize=100
EndSub
Sub OnButtonClicked
LastButton = Controls.LastClickedButton
If (LastButton = StartButton) Then
GraphicsWindow.Clear()
GraphicsWindow.DrawText(250, 100, "Vyber si část světa")
UsaButton = Controls.AddButton("USA", 180, 360)
CanadaButton = Controls.AddButton("Canada", 430, 360)
GermanyButton = Controls.AddButton("Německo", 840, 360)
RussiaButton = Controls.AddButton("Rusko", 200, 520)
ItalyButton = Controls.AddButton("Itálie", 550, 520)
CzechButton = Controls.AddButton("Česko" , 860, 520)
ElseIf (LastButton = UsaButton) Then
Usa1:
DrawQuestionBox()
question = 1
GraphicsWindow.FontSize=80
GraphicsWindow.DrawText(350, 240, "První prezident?")
UsaQuestion1Answer1 = Controls.AddButton("Joe Biden", 200, 430)
UsaQuestion1Answer2 = Controls.AddButton("Barack Obama", 700, 430)
UsaQuestion1Answer3r = Controls.AddButton("George Washington", 370, 570)
elseIf (LastButton = UsaQuestion1Answer1) or (LastButton = UsaQuestion1Answer2) or (LastButton = UsaQuestion2Answer1) or (LastButton = UsaQuestion2Answer3) or (LastButton = UsaQuestion3Answer1) or (LastButton = UsaQuestion3Answer3) or (LastButton = UsaQuestion4Answer2l) or (LastButton = UsaQuestion4Answer3l) Then
DrawWrongBox()
NumberOfWrongAnswers = NumberOfWrongAnswers + 1
elseIf (LastButton = ZnovaButton) then
If question = 1 then
Goto Usa1
elseif question = 2 then
Goto Usa2
elseif question = 3 then
Goto Usa3
Elseif question = 4 then
Goto Usa4
EndIf
elseif (LastButton = UsaQuestion1Answer3r) or (LastButton = UsaQuestion2Answer2r) or (LastButton = UsaQuestion3Answer2r) then
DrawRightBox()
elseif (LastButton = UsaQuestion4Answer1rl) then
DrawFinishBox()
elseif (LastButton = AllDoneButton) then
Goto Start
elseif (LastButton = MenuButton) then
Goto Start
elseif LastButton = NextButton then
If question = 1 then
question = 2
Usa2:
DrawQuestionBox()
GraphicsWindow.FontSize=80
GraphicsWindow.DrawText(270, 240, "Kolik tam žije obyvatel?")
UsaQuestion2Answer1 = Controls.AddButton("220M", 300, 430)
UsaQuestion2Answer2r = Controls.AddButton("330M", 550, 430)
UsaQuestion2Answer3 = Controls.AddButton("1000M", 800, 430)
elseif question = 2 then
question = 3
Usa3:
DrawQuestionBox()
GraphicsWindow.FontSize=80
GraphicsWindow.DrawText(270, 240, "Jaké je hlavní město?")
UsaQuestion3Answer1 = Controls.AddButton("Ohio", 100, 430)
UsaQuestion3Answer2r = Controls.AddButton("Washington D.C.", 300, 430)
UsaQuestion3Answer3 = Controls.AddButton("NewYork", 983, 430)
elseif question = 3 then
question = 4
Usa4:
DrawQuestionBox()
GraphicsWindow.FontSize=80
GraphicsWindow.DrawText(230, 240, "Kdo objevil tento kontinent?")
UsaQuestion4Answer1rl = Controls.AddButton("Kolumbus", 200, 430)
UsaQuestion4Answer2l = Controls.AddButton("Taras Povoroznyk", 650, 430)
UsaQuestion4Answer3l = Controls.AddButton("Neil Armstrong", 400, 570)
EndIf
EndIf
EndSub
StartButton = Controls.AddButton("START", 550, 360)

Small BASIC
Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
277 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. WhTurner 1,611 Reputation points
    2022-12-07T18:31:28.843+00:00

    Can you describe what doesn't work? The program runs and I can click on the buttons. I cannot read your language so I can't see if the right response follows the button click.


  2. WhTurner 1,611 Reputation points
    2022-12-07T18:55:40.53+00:00

    I translated some of the questions with Google Translate, so I could see what happens.
    I expect the problem is caused by the use of GoTo. The use of Goto is stronly discouraged. Try to rewrite the program without GoTo'd.


  3. Scout 136 Reputation points
    2022-12-07T22:01:54.327+00:00

    Here's a quick and dirty fix:
    Change the main program block to a subprogram (Start-Label to Sub Start)
    268326-startsub.png

    Instead of Goto Start: use Start()
    268327-callstartsub.png

    But try to rewrite the program and move the program logic with subprogram calls into a main loop.
    And if possible without Goto's (=NoGo's).
    If it does, then only in the locally manageable area, since collateral damage often occurs with global GoTo's.