I'm trying to set up a screen where the player can choose one of a number of challenges/minigames to be the next one to attempt. To make expanding the set of challenges easier, I have them stored as dicts in a list with keys to show if it is available / prioritised. I'm trying to use a textbutton to toggle the prepared key. The screen is called using a call screen statement.
The screen displays ok and clicking on the textbutton does indeed seem to toggle to the selection on my screen, but it's not changing the underlying dict. Going out of the screen and in again just resets everything (even opening the console and closing it). I've tried a number of ways of doing this (calling a function, using setDict, using enumerate in the for loop to get an index etc), but there is clearly something fundamental I'm missing. It seems clear from my testing that while a local copy of the variables are being updated the global variables are not, and that's why it keeps reverting.
Have searched through the online documentation and various topics on here, but can't work out what is happening. Any ideas what I'm doing wrong? Thanks!
Code: Select all
default challenges = [
{ 'Available' : True,
'Prepared' : False,
'Name' : 'horse riding challenge'},
{ 'Available' : True,
'Prepared' : False,
'Name' : 'swimming challenge'} #etc
]
screen Laptop_Challenges():
use Laptop_screen(_("Challenge Planner"), scroll = "viewport"):
hbox:
grid 1 2:
frame:
xsize 100
ysize 200
text "Skill games" size 22
frame:
xsize 100
ysize 200
text "Puzzles" size 22
grid 4 2:
for c in challenges:
frame:
xsize 200
ysize 200
textbutton c['Name'] action [ToggleDict(c,'Prepared')] sensitive c['Available']