Menu question

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
Thundy
Regular
Posts: 88
Joined: Tue Dec 05, 2017 9:08 am
Contact:

Menu question

#1 Post by Thundy »

Ahoy!

Time for another puzzler

I have a class called Dialogue, which consists of a text item for a menu, an isActive flag and a function name

When creating a menu of these items i can happily check the item is active and if so present the user with a menu item that calls the function.

So far so good,

What I want to avoid is having to do this for every single dialogue i create though so i have an array (list) of dialogue items

Im running into issues when i try to create a menu of these items though. I can manually go through every item in the list and only display the item if isActive is set but over the course of creating the game this could lead to thousands of lines of code just to check which dialogues are active and which arent

Is there a way to create a loop inside the menu: I cant work it out

Code: Select all

menu:
      for q in DIALOGUES:
               "[q.menuText]" if q.isActive:
                       call expression q.function

was my best guess and it doesn't work

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: Menu question

#2 Post by Remix »

renpy.display_menu(
[ ( q.menuText, q.function ) for q in DIALOGUES if q.isActive ], interact=True, screen="choice" )

*might* work... I'm semi guessing on passing q.function as the _return value working as a ChoiceReturn properly.

Sub-note: 'for' loops do not work in labels, so I guess they also do not in menu blocks. 'while' loops do work in labels though, so there is a slim chance a while block could work there too...
Frameworks & Scriptlets:

Thundy
Regular
Posts: 88
Joined: Tue Dec 05, 2017 9:08 am
Contact:

Re: Menu question

#3 Post by Thundy »

Awesome thanks. i will see how that comes out.

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: Menu question

#4 Post by Remix »

An alternative using lambda:0 (dot notation lookup basic objects) to dynamically build the items...
Likely closer to what you were originally trying

Feel free to amend to suit
Basically you just want to create the menu_items list as items similar to a normal menu ( with caption and action )

Code: Select all

label choose_event:
    # a simple label to move location or choose event

    python:
        menu_items = []

        # events
        for label_name in event_handler.labels:
            if some_activity_test: 
                item = lambda:0
                item.action = [ Function( renpy.hide_screen, 'choice'), Jump( label_name ) ]
                item.caption = " ".join( [v.capitalize() for v in label_name.split('_')] )
                menu_items.append( item )

        if not len( menu_items ):
                item = lambda:0
                item.action = [ Function( renpy.hide_screen, 'choice'), Jump( 'end_of_game' ) ]
                item.caption = "There may be no events left. Finish now?"
                menu_items.append( item )


    show screen choice( menu_items )

    # if show and not call, add a dialogue after
    "It is [event_handler] \
    \nYou are in the [location] Sector deciding what to do"

    # if menu choice not jumped, reshow menu
    jump choose_event
Frameworks & Scriptlets:

Thundy
Regular
Posts: 88
Joined: Tue Dec 05, 2017 9:08 am
Contact:

Re: Menu question

#5 Post by Thundy »

Thanks for that. I tried the while loop and the first bit of code to no avail. I will break down this code and see if I can implement it.

Post Reply

Who is online

Users browsing this forum: Google Feedfetcher