For loops, list, and screens
Posted: Thu Jan 16, 2020 2:52 am
Can someone please explain to me why sometimes a for loop works and sometimes it doesn't in screen language?
I can easily display a list of strings by using a for loop, such as party members. However, if I try to change the list while showing the screen it doesn't update. What is the work around to making something simple like the following code work as intended?
The intent is that you can add the names to the pre-defined list and remove them as many times as you want. You hit confirm when you're happy with the list. However, it doesn't work. The screen doesn't update and sometimes when you start the game it already has a name inside of it. I'm not sure what's going on with the code, but any help would be appreciated.
I can easily display a list of strings by using a for loop, such as party members. However, if I try to change the list while showing the screen it doesn't update. What is the work around to making something simple like the following code work as intended?
Code: Select all
define party_list = []
init python:
global party_list
def add_member(name):
if name not in party_list:
party_list.append(name)
def remove_member(name):
if name in party_list:
party_list.remove(name)
screen party_status():
vbox:
label "Current Party"
for i in party_list:
textbutton i action Function("remove_member(i)")
label "Out of party, click to add them."
textbutton "Terra" action Function(add_member('Terra'))
textbutton "Celest" action Function("add_member", 'Celest')
textbutton "Locke" action Function("add_member", 'Locke')
null height 100
textbutton "Confirm" action Return()
screen my_party:
hbox:
xalign 0.9 spacing 25
for name in party_list:
label name text_size 50
label start:
$ party_list = []
call screen party_status
show screen my_party
vt "Eir appears from the left."
"Eir" "Looks like we're making some progress."
return