randomly move of shapes in small basic

Nakanishi Tetsumo 1 Reputation point
2022-02-11T08:19:46.47+00:00

I want to make a program in small basic who has a shape . I want that shape randomly
move to "800,400" or "700,400 " . It means a shape move "800,400" or "700,400" randomly. help please !

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

2 answers

Sort by: Most helpful
  1. WhTurner 1,611 Reputation points
    2022-02-11T13:57:19.167+00:00

    if Math.GetRandomNumber(2)=1 Then
    Shapes.Move(shape,800,400)
    Else
    Shapes.Move(shape,700,400)
    EndIf

    Or:
    rand=Math.GetRandomNumber(2)
    Shapes.Move(shape,600+100*rand,400)

    1 person found this answer helpful.
    0 comments No comments

  2. JR 126 Reputation points
    2022-02-12T02:39:42.13+00:00

    Here's another way of doing it using a timer that is set at random timer.intervals.

    GraphicsWindow.height=600
    GraphicsWindow.width=1000
    MyShape=Shapes.AddRectangle(100,100)
    Timer.Tick=OnTimerTick
    Timer.Interval=1000
    Tick="False"
    Shapes.Move(MyShape,800,400)
    While "True"
    If Tick = "True" and Shapes.GetLeft(MyShape)=800 then
    Shapes.Move(MyShape,700,400)
    Tick="False"
    ElseIf Tick="True" and Shapes.GetLeft(MyShape)=700 then
    Shapes.Move(MyShape,800,400)
    Tick="False"
    EndIf
    Timer.Interval= Math.GetRandomNumber(1000)
    Program.Delay(50)
    EndWhile

    Sub OnTimerTick
    Tick="True"
    EndSub

    JR

    1 person found this answer helpful.
    0 comments No comments