List problem

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
SteelRazer
Newbie
Posts: 10
Joined: Thu Dec 06, 2018 12:25 pm
Contact:

List problem

#1 Post by SteelRazer »

Hello
I want to print a list as days in a viewport
I have a problem with printing the list, basically it has problem with indices I don't know how to fix. In python shell it works when I use i but not in ren'py.
(List indices must be integers, not unicode)

Code: Select all

define days = ['mon','tue','wen','thu']

screen days_screen():

    frame:
        
        viewport:
            scrollbars "vertical"
            xmaximum 500
            mousewheel True
            draggable True
            has vbox

            $ rows = len(days)
            for i in range(0, len(days)):
                        
                text "[days[i]]"


label start:

    call screen days_screen

    return
If it's in a wrong thread, move it there.
Thanks everybody for help

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

Re: List problem

#2 Post by Alex »

That happened 'cause you showing text in a screen, try it like

Code: Select all

default my_list = ["one", "two", "three"]

screen list_scr():
    vbox:
        align(0.2, 0.1)
        for i in range(0, len(my_list)):
            text "%s" % my_list[i]
            
    vbox:
        align(0.4, 0.1)
        for i in my_list:
            text"[i]"
    
label start:
    scene black
    "..."
    show screen list_scr
    "?"

SteelRazer
Newbie
Posts: 10
Joined: Thu Dec 06, 2018 12:25 pm
Contact:

Re: List problem

#3 Post by SteelRazer »

It works but breaks the viewport idea. I want to be able to add x items to the list and then have it displayed in a viewport.
but your

Code: Select all

text "%s" % my_list[i]
solved the problem. Also is there any way to add to the text like textbutton a hover action to show an image? For example with your list, when I would hover over a 1 it would show a image on x,y pos on the screen. Simply adding a hovered with image to a textbutton makes it unresponsive

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

Re: List problem

#4 Post by Alex »

Actually, for i in my_list - is more preferable way.
And what's wrong with putting it inside a viewport?

You can add a hovered action of showing screen that contains an image and unhovered action of hiding that screen.

Code: Select all

image img_1:
    "img_1.png"
    
image img_2:
    "img_2.png"
    
image img_3:
    "img_3.png"
    
    
default my_list = [["one","img_1"], ["two", "img_2"], ["three", "img_3"]]

screen img_scr(img=None):
    add img align(0.4, 0.1)
    #text img align(0.4, 0.1)
    
screen list_scr():

    vbox:
        align(0.2, 0.1)
        for i in my_list:
            textbutton str(i[0]) action [[]] hovered Show("img_scr", img=i[1]) unhovered Hide("img_scr")
    
label start:
    scene black
    "..."
    show screen list_scr
    "?"
https://www.renpy.org/doc/html/screens.html#textbutton
https://www.renpy.org/doc/html/screen_actions.html#Hide

SteelRazer
Newbie
Posts: 10
Joined: Thu Dec 06, 2018 12:25 pm
Contact:

Re: List problem

#5 Post by SteelRazer »

Work very well. I just meant that your code didn't use my viewport originally but I got it already working in viewport. Just one last thing what is that action you used in list_scr. And thank you so much.

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

Re: List problem

#6 Post by Alex »

Well, to be sensitive (change its state, do hovered/unhovered actions) button must have an action

Code: Select all

textbutton "x_x" action None
is insensitive.

So, if you don't have an actual action for the button you can use NullAction() or an empty list of action [[]]
('cause you can set a list of actions for the button, like)

Code: Select all

textbutton "!!!" action [Show("some"screen"), Hide("the_other_screen")]
https://www.renpy.org/doc/html/screen_a ... NullAction

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot], Sugar_and_rice, voluorem