'How to use variables in text function in pgzero
In my game, I want to make a score function. How to make it to display variables in the pgzero text funtion
the code to display text is:
screen.draw.text(score, (70, 30), color="orange")
but an error comes up like this: AttributeError: 'int' object has no attribute 'replace'
how can I display a variable in the screen.draw.text function?
Solution 1:[1]
You must provide a string to the text function. Your score variable probably contains an int value. Use the str function to convert the contents of the score variable to a string:
screen.draw.text(str(score), (70, 30), color="orange")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | r0the |
