I’m trying to make a red light green light game, but I forgot how random works in pygame, I have a square (the player) and the lights, red, yellow, and green, yellow always comes before red, but I just don’t know how to make it work with the randomly choosing green or yellow. Please help!
If you use random.choice it should give you a random selection from a list.
lights = [yellow_light, green_light]
next_light = random.choice(lights)
That looks like it would work.
Also, please post the code as text in a codeblock - you do this by enclosing it in 3 backticks ``` like that.
```
code
```
Like that.
Some pointers to move forward
- random.randint(0, 1) can be used like that.
- Based on your current state you need to do the state transition
- when “green or red”
- select randomly the new target
- change the states based on the selected
- next_light == red and current_light == green => change state to yellow
- add the other cases
- when yellow
- change state to red
- when “green or red”
- having 60 FPS limit is good
- when your state transitions works try moving to a
pygame.timebased version instead of the modulus 60 on the counter
- when your state transitions works try moving to a


