How can i make a variable choose between two other variables?

217 Views Asked by At

So i am making a small homework assignment that should draw a cloud (its kinda wierd but doesn't matter. And i need a variable to choose between 2 other variables like this:

A = 1
B = 2

C = A or B

I thought about using an array but is do not really understand them.

PX_P = PX_1 + Math.GetRandomNumber(300) + 50
PX_N = PX_1 - Math.GetRandomNumber(300) + 50
PY_P = PY_1 + Math.GetRandomNumber(150) + 50
PY_N = PY_1 - Math.GetRandomNumber(150) + 50

PX_2 = (PX_2 should either be PX_P or PX_N)
PY_2 = (PY_2 should either be PY_P or PY_N)
GraphicsWindow.DrawEllipse((PX_2), (PY_2), (SX_2), (SY_2))
GraphicsWindow.FillEllipse((PX_2), (PY_2), (SX_2), (SY_2))
2

There are 2 best solutions below

0
Roshan On

Create a list and using Math.GetRandomNumber() Get an value

list[1] = PX_P
list[2] = PY_N
PX_2 = list[Math.GetRandomNumber(2)]
PY_2 = list[Math.GetRandomNumber(2)]
1
CodeAlong On

You could use this code:

A = 1 'Set the A variable
B = 2 'Set the B variable
num = Math.GetRandomNumber(2) 'Gets a random number between 1 and 2
If num = 2 Then
  C = A
Else
  C = B
EndIf