Reversing a list in a vbox

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
Cazad0ra
Newbie
Posts: 22
Joined: Wed May 19, 2021 3:53 pm
Contact:

Reversing a list in a vbox

#1 Post by Cazad0ra »

Hi! I'm trying to make a quest log screen, but I need to reverse the order of the quest list so that the newest one appears at the top of the list instead of the bottom. I tried box_reverse but that of course reversed the vbox buttons, but not the quest list ^^"

Here's my code

Code: Select all

screen questinfo:
    add "images/quest/quest_info_frame.png"

    $start = quest_page * maxperpage
    $end = min(start + maxperpage - 1, len(questlog) - 1)

    modal True



    vbox:
        area (648, 268, 290, 395)
        for i in range(start, end + 1):
            frame:
                $questlogi = questlog[i]
                style "questframe"
                textbutton "[questlogi.name]":
                    style "questframe"
                    text_style "questframe_text"
                    action [SetVariable("selected_quest", questlog[i]), Show("questdetails")]





        for i in range(end - start +1, maxperpage):
            null

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Reversing a list in a vbox

#2 Post by Remix »

for i in range(end, start - 1, -1):

begins at end... steps using minus 1 (the 3rd parameter) and ends at one step before start - 1, aka start
Frameworks & Scriptlets:

Cazad0ra
Newbie
Posts: 22
Joined: Wed May 19, 2021 3:53 pm
Contact:

Re: Reversing a list in a vbox

#3 Post by Cazad0ra »

Remix wrote: Fri May 21, 2021 12:38 pm for i in range(end, start - 1, -1):

begins at end... steps using minus 1 (the 3rd parameter) and ends at one step before start - 1, aka start
Thanks! It did work for the biggest part, however, the moment the list has more items than "maxperpage", the newest item gets on top, but of the second page.

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

Re: Reversing a list in a vbox

#4 Post by Alex »

The other way you could do it would be not to append quests to a list but to insert them at index 0

Code: Select all

 $ list_name.insert(0, "quest_name")

Cazad0ra
Newbie
Posts: 22
Joined: Wed May 19, 2021 3:53 pm
Contact:

Re: Reversing a list in a vbox

#5 Post by Cazad0ra »

Alex wrote: Fri May 21, 2021 1:28 pm The other way you could do it would be not to append quests to a list but to insert them at index 0

Code: Select all

 $ list_name.insert(0, "quest_name")
Thanks! I tried it, but it gave me an error I somehow don't get when appending:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 125, in script
    niz "Good evening!"
  File "game/scripts/quest_screen.rpy", line 31, in execute
    screen questinfo:
  File "game/scripts/quest_screen.rpy", line 31, in execute
    screen questinfo:
  File "game/scripts/quest_screen.rpy", line 41, in execute
    vbox:
  File "game/scripts/quest_screen.rpy", line 43, in execute
    for i in range(start, end + 1):
  File "game/scripts/quest_screen.rpy", line 44, in execute
    frame:
  File "game/scripts/quest_screen.rpy", line 47, in execute
    textbutton "[questlogi.name]":
AttributeError: 'unicode' object has no attribute 'name'


Cazad0ra
Newbie
Posts: 22
Joined: Wed May 19, 2021 3:53 pm
Contact:

Re: Reversing a list in a vbox

#6 Post by Cazad0ra »

Alex wrote: Fri May 21, 2021 1:28 pm The other way you could do it would be not to append quests to a list but to insert them at index 0

Code: Select all

 $ list_name.insert(0, "quest_name")
Nevermind, I made a typo, this worked like a charm, thanks!!

Post Reply

Who is online

Users browsing this forum: Google [Bot]