I have a list of "guys" in my game that can increase over time without a limit. I want to have a screen that displays every name of the guys. I tried that with a scrollable screen but i'm struggling with actually having the names show up here is what i was planning:
Code: Select all
screen listGuys():
frame:
xalign 0.5 ypos 50
vbox:
spacing 10
side ("c r"):
area (1,0,280,600)
viewport id "my_scroller": #REMEMBER YOUR VIEWPORT ID SO THE SCROLLBAR IS PLACED FOR IT
draggable True mousewheel True
vbox:
spacing 5
for i in len(guys):
textbutton guys[i].name action Return(i)
vbar value YScrollValue("my_scroller") #TAKES YOUR VIEWPORT ID AS THE ARG
button:
action [Jump("start")]
text "Go Back" style "button_text"
init python:
class Guy:
def __init__(self, name):
self.name=name
label start:
$g1=Guy("Fred")
$g2=Guy("Pep")
$g3=Guy("Doobie")
$guys=[g1,g2,g3]
show screen listGuys
pause
Eventually i got it to work with this screen:
Code: Select all
screen listGuys():
frame:
xalign 0.5 ypos 50
vbox:
spacing 10
side ("c r"):
area (1,0,280,600)
viewport id "my_scroller": #REMEMBER YOUR VIEWPORT ID SO THE SCROLLBAR IS PLACED FOR IT
draggable True mousewheel True
vbox:
spacing 5
for i, guys in enumerate(guys):
textbutton guys.name action Return(i)
vbar value YScrollValue("my_scroller") #TAKES YOUR VIEWPORT ID AS THE ARG
button:
action [Jump("start")]
text "Go Back" style "button_text"
Does anyone know how i can display the list without the exception ocurring or does anyone have a better solution for my idea?TypeError: 'Guy' not iterable