Dynamic menu choices from array/list [SOLVED]

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
User avatar
JackDoe
Newbie
Posts: 15
Joined: Sun Aug 12, 2018 10:28 am
Contact:

Dynamic menu choices from array/list [SOLVED]

#1 Post by JackDoe »

Hello!

I wonder if it's possible to dynamically create menu choices from array in RenPy? Let's say you have 100 skills in the game, and player can use 1-5 of them (like in any rpg). Is it possible to display current skillset as a menu choices and remember the one that player picked? I wrote the following code, obviously it doesn't work:

Code: Select all

python:
        menu_items = []
        for item in player.skills:
            menu_items.append(skillsList[item].name)
        choice = menu(menu_items)
        for i in Skill.name:
            if Skill.name == choice:    
                chosen_skill = choice
    #CalculateDamage(player, enemy, chosen_skill)	

Edit: correct code is as follow:

Code: Select all

menu_items = []
        for item in player.skills:
            menu_items.append(skillsList[item].name)
        choice = renpy.display_menu([(skill, skill) for skill in menu_items])
Last edited by JackDoe on Thu Feb 21, 2019 11:20 am, edited 1 time in total.


User avatar
JackDoe
Newbie
Posts: 15
Joined: Sun Aug 12, 2018 10:28 am
Contact:

Re: Dynamic menu choices from array/list

#3 Post by JackDoe »

Alex wrote: Wed Feb 20, 2019 11:44 am it might be easier to use a screen.
Thank you!
No idea how it will help me

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

Re: Dynamic menu choices from array/list

#4 Post by Alex »

:-))) Instead of calling a menu call a custom screen with bunch of buttons that will let player to choose skills and all.

User avatar
JackDoe
Newbie
Posts: 15
Joined: Sun Aug 12, 2018 10:28 am
Contact:

Re: Dynamic menu choices from array/list

#5 Post by JackDoe »

Alex wrote: Wed Feb 20, 2019 3:19 pm :-))) Instead of calling a menu call a custom screen with bunch of buttons that will let player to choose skills and all.
The question is how to make these buttons dynamically from the array.
Never use screens before. :?

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

Re: Dynamic menu choices from array/list

#6 Post by Alex »

JackDoe wrote: Thu Feb 21, 2019 12:03 am The question is how to make these buttons dynamically from the array.
Never use screens before. :?
Mmm, try something like

Code: Select all

screen my_scr():
    vbox:
        align (0.5, 0.5)
        for item in player.skills:
            var = skillsList[item].name
            textbutton "[var]" action Return(var)

label start:
    "..."
    call screen my_scr
    $ res = _return
    "[res]"
    "?"
https://www.renpy.org/doc/html/screens.html#call-screen

Post Reply

Who is online

Users browsing this forum: Google [Bot]