Page 1 of 1
List problem
Posted: Thu Dec 06, 2018 1:11 pm
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
Re: List problem
Posted: Thu Dec 06, 2018 2:23 pm
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
"?"
Re: List problem
Posted: Thu Dec 06, 2018 2:37 pm
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
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
Re: List problem
Posted: Thu Dec 06, 2018 4:40 pm
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
Re: List problem
Posted: Thu Dec 06, 2018 5:03 pm
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.
Re: List problem
Posted: Thu Dec 06, 2018 5:16 pm
by Alex
Well, to be sensitive (change its state, do hovered/unhovered actions) button must have an action
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