none
Small Basic error RRS feed

  • Question

  • Hi, i keep getting an error as because i call a goto inside a sub. My problem is i need the goto to be in the sub for the program i have made to work.

    The program is a simple gameloader for my retro game console OS that i am developing in small basic then using the migrate tool and some other converters to get it an OS.

    here's my code:

    loadGame1:
    Sound.PlayChime()
    Goto start
    loadGame2:
    Goto start
    loadGame3:
    Goto start
    Run:
    GraphicsWindow.KeyDown = event
    GraphicsWindow.MouseDown = event2
    Sub event
      If (Shapes.GetTop(pointer)) = 44 Then
        Shapes.Move(pointer,50,4)
      ElseIf (Shapes.GetTop(pointer)) = 4 then
        Shapes.Move(pointer,50,24)
      Else
        Shapes.Move(pointer,50,44)
      EndIf
    EndSub
    Program.Delay(500)

    event2:
    If (Shapes.GetTop(pointer)) = 44 Then
      Goto loadGame3
    ElseIf (Shapes.GetTop(pointer)) = 4 then
      Goto loadGame1
    Else
      Goto loadGame2
    EndIf

    Please find a way arround it that works.

    Monday, June 17, 2019 5:54 PM

Answers

  • Hi,

    Still not really sure what it is supposed to do, but here is how I would start structuring it (based on the links I gave).

    '====================================================================
    ' MAIN PROGRAM LOGIC
    '====================================================================
    
    Initialise()
    
    While ("True")
      If (game = 1) Then
        Sound.PlayChime()
      ElseIf (game = 2) Then
        Sound.PlayBellRing()
      ElseIf (game = 3) Then
        Sound.PlayClick()
      EndIf
      
      game = 0 'Wait for next game ?
      Program.Delay(20)
    EndWhile
    
    '====================================================================
    ' SUBROUTINES
    '====================================================================
    Sub Initialise
      GraphicsWindow.Title = "Foxstrike GameSystem"
      GraphicsWindow.BackgroundColor = "darkorange"
      GraphicsWindow.Width = 600
      GraphicsWindow.Height = 400
      TextWindow.ForegroundColor = "green"
      GraphicsWindow.BrushColor = "black"
      TextWindow.WriteLine("loading graphics...")
      GraphicsWindow.FontSize = 30
      TextWindow.WriteLine("loading programing...")
      title = Shapes.AddText("Foxstrike Computing")
      TextWindow.WriteLine("loading extras")
      Shapes.HideShape(title)
      TextWindow.WriteLine("RPGP Ready...")
      Program.Delay(1000)
      TextWindow.Hide()
      Shapes.Move(title, -100,-100)
      Shapes.ShowShape(title)
      Shapes.Animate(title,200,200,1000)
      Sound.PlayChimesAndWait()
      Program.Delay(2000)
      Shapes.HideShape(title)
      GraphicsWindow.Clear()
      GraphicsWindow.FontSize = 15
      GraphicsWindow.BackgroundColor = "black"
      GraphicsWindow.FontName = "Consolas"
      Shapes.Remove(title)
      GraphicsWindow.BrushColor = "white"
      game1 = Shapes.AddText("Game 1")
      game2 = Shapes.AddText("Game 2")
      game3 = Shapes.AddText("Game 3")
      Shapes.Move(game2,0,20)
      Shapes.Move(game3,0,40)
      pointer = Shapes.AddRectangle(10,10)
      Shapes.Move(pointer,50,4)
      
      game = 0 'Initially game unset
      
      GraphicsWindow.KeyDown = OnKeyDown
      GraphicsWindow.MouseDown = OnMouseDown
    EndSub
    
    '====================================================================
    ' EVENT SUBROUTINES
    '====================================================================
    
    Sub OnKeyDown 'Move game indicator
      If (Shapes.GetTop(pointer)) = 44 Then
        Shapes.Move(pointer,50,4)
      ElseIf (Shapes.GetTop(pointer)) = 4 Then
        Shapes.Move(pointer,50,24)
      Else
        Shapes.Move(pointer,50,44)
      EndIf
    EndSub
    
    Sub OnMouseDown 'Set game using game indicator
      If (Shapes.GetTop(pointer)) = 44 Then
        game = 3
      ElseIf (Shapes.GetTop(pointer)) = 4 Then
        game = 1
      Else
        game = 2
      EndIf
    EndSub

    Monday, June 17, 2019 6:59 PM
    Moderator

All replies

  • Hi,

    I'm sorry, but I have no idea what your code is designed to do, so can't suggest how to change it. There is no Start:, what is pointer, event2 should be a subroutine and the overall purpose is unclear - partly due to GoTo statements that make it hard to read.

    However:

    1] You cannot use a GoTo to jump into or out of a subroutine - no exceptions.

    2] In general you should try not to use GoTo if possible - it will create code that is hard to debug or maintain - there are almost always better ways.

    3] Make sure you are clear how events work in Small Basic.. Perhaps try to use a game-loop to control the main flow logic.

    Here are some links to some resources that may be helpful.

    https://social.technet.microsoft.com/wiki/contents/articles/15081.small-basic-programming-tips.aspx

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

    Monday, June 17, 2019 6:30 PM
    Moderator
  • start is at the top as this was a snipit, here is the main program:

    start:
    GraphicsWindow.Title = "Foxstrike GameSystem"
    GraphicsWindow.BackgroundColor = "darkorange"
    GraphicsWindow.Width = 600
    GraphicsWindow.Height = 400
    TextWindow.ForegroundColor = "green"
    GraphicsWindow.BrushColor = "black"
    TextWindow.WriteLine("loading graphics...")
    GraphicsWindow.FontSize = 30
    TextWindow.WriteLine("loading programing...")
    title = Shapes.AddText("Foxstrike Computing")
    TextWindow.WriteLine("loading extras")
    Shapes.HideShape(title)
    TextWindow.WriteLine("RPGP Ready...")
    Program.Delay(1000)
    TextWindow.Hide()
    Shapes.Move(title, -100,-100)
    Shapes.ShowShape(title)
    Shapes.Animate(title,200,200,1000)
    Sound.PlayChimesAndWait()
    Program.Delay(2000)
    Shapes.HideShape(title)
    GraphicsWindow.Clear()
    GraphicsWindow.FontSize = 15
    GraphicsWindow.BackgroundColor = "black"
    GraphicsWindow.FontName = "Consolas"
    Shapes.Remove(title)
    GraphicsWindow.BrushColor = "white"
    game1 = Shapes.AddText("Game 1")
    game2 = Shapes.AddText("Game 2")
    game3 = Shapes.AddText("Game 3")
    Shapes.Move(game2,0,20)
    Shapes.Move(game3,0,40)
    pointer = Shapes.AddRectangle(10,10)
    Shapes.Move(pointer,50,4)
    Goto Run
    loadGame1:
    Sound.PlayChime()
    Goto start
    loadGame2:
    Goto start
    loadGame3:
    Goto start
    Run:
    GraphicsWindow.KeyDown = event
    GraphicsWindow.MouseDown = event2
    Sub event
      If (Shapes.GetTop(pointer)) = 44 Then
        Shapes.Move(pointer,50,4)
      ElseIf (Shapes.GetTop(pointer)) = 4 then
        Shapes.Move(pointer,50,24)
      Else
        Shapes.Move(pointer,50,44)
      EndIf
    EndSub
    Program.Delay(500)

    event2:
    If (Shapes.GetTop(pointer)) = 44 Then
      Goto loadGame3
    ElseIf (Shapes.GetTop(pointer)) = 4 then
      Goto loadGame1
    Else
      Goto loadGame2
    EndIf

    sorry for not being more specific that it was only a snipit.

    Monday, June 17, 2019 6:43 PM
  • the load games are in the middle because at the end it would skip the subs and end the game

    Monday, June 17, 2019 6:44 PM
  • Hi,

    Still not really sure what it is supposed to do, but here is how I would start structuring it (based on the links I gave).

    '====================================================================
    ' MAIN PROGRAM LOGIC
    '====================================================================
    
    Initialise()
    
    While ("True")
      If (game = 1) Then
        Sound.PlayChime()
      ElseIf (game = 2) Then
        Sound.PlayBellRing()
      ElseIf (game = 3) Then
        Sound.PlayClick()
      EndIf
      
      game = 0 'Wait for next game ?
      Program.Delay(20)
    EndWhile
    
    '====================================================================
    ' SUBROUTINES
    '====================================================================
    Sub Initialise
      GraphicsWindow.Title = "Foxstrike GameSystem"
      GraphicsWindow.BackgroundColor = "darkorange"
      GraphicsWindow.Width = 600
      GraphicsWindow.Height = 400
      TextWindow.ForegroundColor = "green"
      GraphicsWindow.BrushColor = "black"
      TextWindow.WriteLine("loading graphics...")
      GraphicsWindow.FontSize = 30
      TextWindow.WriteLine("loading programing...")
      title = Shapes.AddText("Foxstrike Computing")
      TextWindow.WriteLine("loading extras")
      Shapes.HideShape(title)
      TextWindow.WriteLine("RPGP Ready...")
      Program.Delay(1000)
      TextWindow.Hide()
      Shapes.Move(title, -100,-100)
      Shapes.ShowShape(title)
      Shapes.Animate(title,200,200,1000)
      Sound.PlayChimesAndWait()
      Program.Delay(2000)
      Shapes.HideShape(title)
      GraphicsWindow.Clear()
      GraphicsWindow.FontSize = 15
      GraphicsWindow.BackgroundColor = "black"
      GraphicsWindow.FontName = "Consolas"
      Shapes.Remove(title)
      GraphicsWindow.BrushColor = "white"
      game1 = Shapes.AddText("Game 1")
      game2 = Shapes.AddText("Game 2")
      game3 = Shapes.AddText("Game 3")
      Shapes.Move(game2,0,20)
      Shapes.Move(game3,0,40)
      pointer = Shapes.AddRectangle(10,10)
      Shapes.Move(pointer,50,4)
      
      game = 0 'Initially game unset
      
      GraphicsWindow.KeyDown = OnKeyDown
      GraphicsWindow.MouseDown = OnMouseDown
    EndSub
    
    '====================================================================
    ' EVENT SUBROUTINES
    '====================================================================
    
    Sub OnKeyDown 'Move game indicator
      If (Shapes.GetTop(pointer)) = 44 Then
        Shapes.Move(pointer,50,4)
      ElseIf (Shapes.GetTop(pointer)) = 4 Then
        Shapes.Move(pointer,50,24)
      Else
        Shapes.Move(pointer,50,44)
      EndIf
    EndSub
    
    Sub OnMouseDown 'Set game using game indicator
      If (Shapes.GetTop(pointer)) = 44 Then
        game = 3
      ElseIf (Shapes.GetTop(pointer)) = 4 Then
        game = 1
      Else
        game = 2
      EndIf
    EndSub

    Monday, June 17, 2019 6:59 PM
    Moderator
  • ok I will give it a try and get back to you

    Tuesday, June 18, 2019 12:59 PM
  • it workd!

    Thanks for the help!

    Tuesday, June 18, 2019 1:01 PM