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.
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
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...
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