How do I update a text entity contained within a window panel in Ursina?

Viewed 315

Essentially, I am trying to have a scoreboard, which upon completion of a task, opens the scoreboard and displays what your score is. However, whenever I run the actual task, it displays the initial value instead of the new variable value. How could I update this value within the window panel?

Sample Pseudocode:

from ursina import *

score=0

def challenge():
    score += 2
    wp.enabled=True

app = Ursina()

wp = WindowPanel(content=(Text('text' + str(score))) popup=True, enabled=False)

start = Button(parent=scene, text='start', on_click=challenge)

app.run()
2 Answers

Assign the text entity to a variable first:

text_entity = Text('text' + str(score))
wp = WindowPanel(content=(text_entity,) popup=True, enabled=False)

# to update the text
text_entity.text = 'new text'

What is happening is that your not assigning a variable to the Text which is bad. See: wp = WindowPanel(content=(Text('text' + str(score))) popup=True, enabled=False) When You assign it, you can change the information and content. text = Text('text' + str(score)) wp = WindowPanel(content=(text) popup=True, enabled=False) If you want to do something like if a key is pressed, then see this code:

` text = Text('text' + str(score)) wp = WindowPanel(content=(text) popup=True, enabled=False)

def update():

`

Related