How to create a menu for list of obtainable endings?

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
salventus
Newbie
Posts: 20
Joined: Fri Jun 20, 2014 12:16 am
Contact:

How to create a menu for list of obtainable endings?

#1 Post by salventus »

I'm still newbie at coding things, so eventhough in another thread phytom has already explained how to create menu of list obtainable endings like this

Code: Select all

init python
    # If persistent.endings is None (the first pass through the game), then make it a set.
    if persistent.endings is None:
        persistent.endings = set()

    # This shows a single ending, as necessary.
    def show_ending(number, name):
         if name in persistent.endings:
             ui.text("% 2d. %s" % (number, name))
         else:
             ui.text("% 2d. ---------------------------------" % (number,))

    # Add a button that brings people to the ending list to the main menu.
    config.main_menu.insert(2, ("Endings", "endings_1", "True"))

# Jump here to return to the main menu.
label endings_return:
      return

Code: Select all

label endings_1:
    scene bg endings_1
    $ ui.vbox()
    $ show_ending(1, "True Ending")
    $ show_ending(2, "False Ending")
    $ show_ending(3, "Best Ending")
    # ...
    $ show_ending(12, "Etcetera.")
    
    # $ ui.textbutton("Previous Page", clicked=ui.jumps("endings_0")
    $ ui.textbutton("Next Page", clicked=ui.jumps("endings_2")
    $ ui.textbutton("Return", clicked=ui.jumps("endings_return")
    $ ui.close()
     
    $ ui.interact(suppress_overlay=True)  

Code: Select all

label true_ending:
    $ persistent.endings.add("True Ending")
    ".:. True Ending"
    return
I still don't understand where i should put that code and what part do i need to change in order to make my ending list appear like this (For example, like, list of obtainable endings in "Doppelganger" game:

Character A Ending:
1.???
2.???
3.???

Character B Ending:
1.???
2.???
3.???

And so on..

How to do it?

Valmoer
Regular
Posts: 53
Joined: Sat Feb 04, 2012 9:46 pm
Contact:

Re: How to create a menu for list of obtainable endings?

#2 Post by Valmoer »

Short answer : anywhere.

Long answer : Well, first, the code as you got there have a few minor syntax mistakes :
  • init python is missing its colon
  • ui.textbutton("Next Page", clicked=ui.jumps("endings_2") is missing its final parenthesis
  • and so is ui.textbutton("Return", clicked=ui.jumps("endings_return")
Now, for the code itself. First, in renpy, the relative position of the codelines is mostly irrelevant. Not completely, as we all know that in the absence of relevant flow control statements (jump, call...) the lines are interpreted in sequence, but the use of said control statements makes code position a non-issue on a technical point of view (as far as design and human readability is concerned, that's a whole other can of worms, which we shan't open today).

For example, here you have init code, which will by definition be interpreted before any other code in the application.
The rest of the code are labels that can be called or jumped to.

----
Now, for you second question: How to add relevant characters headers to your list. Well - given that your list is a handmade one, you simply have to add the wanted text with the $ ui.text(...) function, for example :

Code: Select all

label endings_1:
    scene bg endings_1
    $ ui.vbox()

    $ ui.text("Character A Endings")
    $ show_ending(1, "A True Ending")
    $ show_ending(2, "A False Ending")
    $ show_ending(3, "A Best Ending")
    $ ui.text("Character B Endings")
    $ show_ending(4, "B True Ending")
    $ show_ending(5, "B False Ending")
    $ show_ending(6, "B Best Ending")
And each time you reach the relevant ending, don't forget to add it to the persistent set : for example, to "unlock" the 5th ending, at your ending scene you'd add $ persistent.endings.add("B False Ending")

salventus
Newbie
Posts: 20
Joined: Fri Jun 20, 2014 12:16 am
Contact:

Re: How to create a menu for list of obtainable endings?

#3 Post by salventus »

Short answer : anywhere.

Long answer : Well, first, the code as you got there have a few minor syntax mistakes :
init python is missing its colon
ui.textbutton("Next Page", clicked=ui.jumps("endings_2") is missing its final parenthesis
and so is ui.textbutton("Return", clicked=ui.jumps("endings_return")

Now, for the code itself. First, in renpy, the relative position of the codelines is mostly irrelevant. Not completely, as we all know that in the absence of relevant flow control statements (jump, call...) the lines are interpreted in sequence, but the use of said control statements makes code position a non-issue on a technical point of view (as far as design and human readability is concerned, that's a whole other can of worms, which we shan't open today).

For example, here you have init code, which will by definition be interpreted before any other code in the application.
The rest of the code are labels that can be called or jumped to.

----
Now, for you second question: How to add relevant characters headers to your list. Well - given that your list is a handmade one, you simply have to add the wanted text with the $ ui.text(...) function, for example :

Code:
label endings_1:
scene bg endings_1
$ ui.vbox()

$ ui.text("Character A Endings")
$ show_ending(1, "A True Ending")
$ show_ending(2, "A False Ending")
$ show_ending(3, "A Best Ending")
$ ui.text("Character B Endings")
$ show_ending(4, "B True Ending")
$ show_ending(5, "B False Ending")
$ show_ending(6, "B Best Ending")


And each time you reach the relevant ending, don't forget to add it to the persistent set : for example, to "unlock" the 5th ending, at your ending scene you'd add $ persistent.endings.add("B False Ending")
it works perfectly :o ! Thank you for explaining me :D
Although there's still something i don't know how to change, like in the pict:
how to move the 'return' button to the bottom of the screen
also, is it possible to click the return button to go back to the main menu, not proceeding to start the game?
Attachments
tes2.png

Valmoer
Regular
Posts: 53
Joined: Sat Feb 04, 2012 9:46 pm
Contact:

Re: How to create a menu for list of obtainable endings?

#4 Post by Valmoer »

salventus wrote:How to move the 'return' button to the bottom of the screen
In a screen, with the screen language, you would add a style property yalign 1.0. Here, per the Screen language / Python method conversion model, you'll add a keyword argument : , yalign=1.0).

You must also get the button out of the vbox (out of between the $ ui.vbox() and $ ui.close() instructions). Otherwise, the button will yalign with the bottom of the vbox rather than with the bottom of the screen, and as the vbox has by definition just the needed size to fit all its elements, the button would therefore stay where it is.

Taking these two modifications into account, your old code

Code: Select all

    $ ui.vbox()
    $ show_ending(1, "True Ending")
    $ show_ending(2, "False Ending")
    $ show_ending(3, "Best Ending")
    # ...
    $ ui.textbutton("Return", clicked=ui.jumps("endings_return"))
    $ ui.close()
thus becomes

Code: Select all

    $ ui.vbox()
    $ show_ending(1, "True Ending")
    $ show_ending(2, "False Ending")
    $ show_ending(3, "Best Ending")
    # ...
    $ ui.close()

    $ ui.textbutton("Return", clicked=ui.jumps("endings_return"), yalign=1.0)
salventus wrote:Also, is it possible to click the return button to go back to the main menu, not proceeding to start the game?
Weird. For me, that code do return to the menu. Where and how exactly do you call the label endings1 (or your equivalent thereof ?

salventus
Newbie
Posts: 20
Joined: Fri Jun 20, 2014 12:16 am
Contact:

Re: How to create a menu for list of obtainable endings?

#5 Post by salventus »

this is what i code

Code: Select all

init python:
    
    # If persistent.endings is None (the first pass through the game), then make it a set.
    if persistent.endings is None:
        persistent.endings = set()

    # This shows a single ending, as necessary.
    def show_ending(number, name):
         if name in persistent.endings:
             ui.text("% 2d. %s" % (number, name))
         else:
             ui.text("% 2d. ???" % (number,))

    # Add a button that brings people to the ending list to the main menu.
    config.main_menu.insert(2, ("Endings", "endings_1", "True"))
    
label Endings:
    scene bg cave
    $ ui.vbox()
        
    $ ui.text("Askary Endings")
    $ show_ending(1, "True Ending")
    $ show_ending(2, "Bad Ending")
    $ show_ending(3, "Worst Ending")
        
    $ ui.close()
    $ ui.textbutton("Return", clicked=ui.jumps("endings_return"), xalign=0.05, yalign=0.95)
     
    $ ui.interact(suppress_overlay=True) 
    
# Jump here to return to the main menu.
label endings_return:
      return
i already work on the return button you explain before, so now i can get that button exactly placed to where i want it :D
Where and how exactly do you call the label endings1 (or your equivalent thereof ?
for this, i call it when coding config.main_menu.insert
and supposedly, the statement i wrote "Jump here to return to the main menu. label ending_return. return" should have taken me back to the main menu right? But no matter what i do to change the code, clicking return button still keeping me proceeding to the start game. Something still wrong with my code?

Post Reply

Who is online

Users browsing this forum: Bing [Bot]