1

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()
  • It won't update automatically because the expression `Text('text' + str(score))` is only evaluated once. In this simple use case, you could recreate the popup every time you need it instead of trying to change an existing one. – Jan Wilamowski Oct 08 '21 at 02:51

2 Answers2

2

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'
pokepetter
  • 1,383
  • 5
  • 8
  • It's also possible to do wp.content[0].text = 'new text', but it's a bit less readable and you depends on the order. – pokepetter Oct 08 '21 at 14:51
0

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():
Lixt
  • 201
  • 4
  • 19
DonYeet46
  • 13
  • 6