I want a randomized pair of shapes to appear on the screen when the game is run and this pair removed and replaced with another pair of shapes when the left shift or right shift button on the keyboard is pressed, using the Ursina Engine in Python. Currently, my code works but it always breaks down when the third pair of shapes appear on the screen. I don't know what exactly the problem is or how to solve it. Any help?
from ursina import *
import random
#creates the instance of the game
app = Ursina()
#contains a list of the shapes
shape_a = [] #set a shapes on the right side
shape_b = [] #set b shapes on the left side
#Entities refer to shapes created that appear in pairs
#SET A
#Visibilities turned off for each entity
s1a = Entity(model = 'cube', color = color.orange, scale = (2,2), position = (-2.5,0,0), rotation = Vec3 (45,45,45), texture = 'white_cube')
s1a.visible = False
s2a = Entity(model = 'cube', color = color.orange, scale = (2,2), position = (-2.5,0,0), rotation = Vec3 (45,-45,45), texture = 'white_cube')
s2a.visible = False
s3a = Entity(model = 'sphere', color = color.orange, scale = (2,2), position = (-2.5,0,0), rotation = Vec3 (45,45,45), texture = 'white_cube')
s3a.visible = False
s4a = Entity(model = 'quad', color = color.orange, scale = (2.5,2), position = (-2.5,0,0), rotation = Vec3 (45,-45,45), texture = 'white_cube')
s4a.visible = False
#Appends each entity to the corresponding list
shape_a.append(s1a)
shape_a.append(s2a)
shape_a.append(s3a)
shape_a.append(s4a)
#Entities refer to shapes created that appear in pairs
#SET B
#Visibilities turned off for each entity
s1b = Entity(model = 'cube', color = color.orange, scale = (2,2), position = (2.5,0,0), rotation = Vec3 (45,45,45), texture = 'white_cube')
s1b.visible = False
s2b = Entity(model = 'cube', color = color.orange, scale = (2.5,2), position = (2.5,0,0), rotation = Vec3 (45,-45,45), texture = 'white_cube')
s2b.visible = False
s3b = Entity(model = 'quad', color = color.orange, scale = (2,2), position = (2.5,0,0), rotation = Vec3 (45,45,45), texture = 'white_cube')
s3b.visible = False
s4b = Entity(model = 'sky_dome', color = color.orange, scale = (0.5,0.5), position = (2.5,0,0), rotation = Vec3 (45,-45,45), texture = 'white_cube')
s4b.visible = False
#Appends each entity to the corresponding list
shape_b.append(s1b)
shape_b.append(s2b)
shape_b.append(s3b)
shape_b.append(s4b)
#Shows the first pair of shapes on the screen.
a = random.choice(shape_a)
a.visible = True
b = random.choice(shape_b)
b.visible = True
#Called to turn off the visibility of the current shapes
def Falsefunction ():
#a = random.choice(shape_a)
a.visible = False
#b = random.choice(shape_b)
b.visible = False
for i in range(1,20):
def input(key):
#receives input from the keyboard
if key == "left shift" or key == "right shift":
Falsefunction()
#After the current pair of shapes disappear from the screen, the next lines of code causes another
#random pair of shapes to appear as long as the loop keeps running.
a = random.choice(shape_a)
a.visible = True
b = random.choice(shape_b)
b.visible = True
app.run()