So basically, I´m buildig the scoring system for a pong game. The global variable s_a is 0 and supposed to change after the ball goes out of bounce.
import turtle
import time
win = turtle.Screen()
win.title("Pong")
win.bgcolor("black")
win.setup(width=800, height=600)
win.tracer(0)
ball = turtle.Turtle()
ball.speed(0)
ball.shape("square")
ball.color("white")
ball.penup()
ball.goto(0, 0)
ball.dx = 2
s_a = 0
s_s = turtle.Turtle()
s_s.speed(0)
s_s.hideturtle()
s_s.goto(0, 0)
s_s.penup()
s_s.color("white")
current_score = "Player A: {} | Player B: 0".format(s_a)
s_s.write(current_score, align="center", font=("Courier", 16, "normal"))
while True:
win.update()
time.sleep( 1 / 60 )
ball.setx(ball.xcor() + ball.dx)
if ball.xcor() > 380:
s_a += 1
ball.goto(0,0)
The ball resets itself and changes direction like supposed to, however the variable doesn´t update. Did I miss something?