0

I need to have a graphics window that displays a message over and over again as a user clicks a button. I have looked all over the internet for instructions on how to not make it overlap. This is most likely a quick fix but idk. Plz help here is my code. I am trying to make a clicker game but haulted as this issue happened.

GraphicsWindow.Height = 420
GraphicsWindow.Width = 720
GraphicsWindow.CanResize = "1"

button = Controls.AddButton("Click for eggs",200,200)
Controls.SetSize(button,100,100)

eggs = 0

Controls.ButtonClicked = buttonClicked

Sub buttonClicked

lastButtonClicked = Controls.LastClickedButton

If lastButtonClicked = button Then
eggs = eggs + 1
GraphicsWindow.DrawText(0,0,"You have " + eggs + " eggs")   
ElseIf eggs >= 1 Then  
GraphicsWindow.BackgroundColor = "White"
GraphicsWindow.DrawText(0,0,"You have " + eggs + " eggs")  
EndIf
EndSub

2 Answers2

0

As far as I know, this exact effect isn't possible in Small Basic, because things drawn to the GraphicsWindow can't be edited or removed without clearing the entire window.

Instead, I would use a TextBox from Controls, which can be edited after they've been created. Because the TextBox can normally be edited by the user, I've also added code to prevent the content from being edited.

See my comments in the code for more about how this works.

GraphicsWindow.Height = 420
GraphicsWindow.Width = 720
GraphicsWindow.CanResize = "1"

button = Controls.AddButton("Click for eggs",200,200)
Controls.SetSize(button,100,100)

eggs = 0

Controls.ButtonClicked = buttonClicked

' Create a text box to show the egg count
myTextBox = Controls.AddTextBox(0, 0)

' Ensure the user can't edit its contents by resetting the text if it changes
Controls.TextTyped = updateEggs

Sub updateEggs
  ' Change the text of myTextBox
  Controls.SetTextBoxText(myTextBox, "You have " + eggs + " eggs")   
EndSub

Sub buttonClicked
  lastButtonClicked = Controls.LastClickedButton

  If lastButtonClicked = button Then
    eggs = eggs + 1
    updateEggs()
  ElseIf eggs >= 1 Then  
    GraphicsWindow.BackgroundColor = "White"
    updateEggs()
  EndIf
EndSub

This GIF demonstrates how the TextBox looks and works, as well as how the text cannot be changed:

GIF

Aaron Christiansen
  • 11,584
  • 5
  • 52
  • 78
0

All you have to do is use Shapes.AddText. This will create a text shape that can be modified with Shapes.SetText

Example:

GraphicsWindow.Height = 420
GraphicsWindow.Width = 720
GraphicsWindow.CanResize = "1"

Text = Shapes.AddText("You have 0 eggs")

button = Controls.AddButton("Click for eggs",200,200)
Controls.SetSize(button,100,100)

eggs = 0

Controls.ButtonClicked = buttonClicked

Sub buttonClicked
lastButtonClicked = Controls.LastClickedButton

If lastButtonClicked = button Then
eggs = eggs + 1
Shapes.SetText(Text,"You have " + eggs + " eggs")   
EndIf
EndSub
Zock77
  • 951
  • 8
  • 26