How to show a potentially infinite list in a screen

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
abduhl
Newbie
Posts: 2
Joined: Tue Jul 18, 2023 1:10 pm
Contact:

How to show a potentially infinite list in a screen

#1 Post by abduhl »

Ok so the title might not be the best but here is my issue:

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
But nothing except for a blank frame showed up.
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"
However every now and then i get the exception:
TypeError: 'Guy' not iterable
Does anyone know how i can display the list without the exception ocurring or does anyone have a better solution for my idea?

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: How to show a potentially infinite list in a screen

#2 Post by enaielei »

Use other name than "guys" in "for i, guys". "guys" is already taken as a name for your list containing the object Guy.

User avatar
Alex
Lemma-Class Veteran
Posts: 3095
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: How to show a potentially infinite list in a screen

#3 Post by Alex »

abduhl wrote: Tue Jul 18, 2023 1:25 pm ...
For your first approach try

Code: Select all

for i in range(len(guys)):

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: How to show a potentially infinite list in a screen

#4 Post by Imperf3kt »

There's also this which I came across recently.
https://youtube.com/shorts/WOxf0xumpWU?feature=share4
May be handy
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

abduhl
Newbie
Posts: 2
Joined: Tue Jul 18, 2023 1:10 pm
Contact:

Re: How to show a potentially infinite list in a screen

#5 Post by abduhl »

I found my mistake i forgot to give the screen my list now its working:)

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Sirifys-Al