Page 1 of 1

Dynamic menu choices from array/list [SOLVED]

Posted: Wed Feb 20, 2019 10:21 am
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])

Re: Dynamic menu choices from array/list

Posted: Wed Feb 20, 2019 11:44 am
by Alex

Re: Dynamic menu choices from array/list

Posted: Wed Feb 20, 2019 11:51 am
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

Re: Dynamic menu choices from array/list

Posted: Wed Feb 20, 2019 3:19 pm
by Alex
:-))) Instead of calling a menu call a custom screen with bunch of buttons that will let player to choose skills and all.

Re: Dynamic menu choices from array/list

Posted: Thu Feb 21, 2019 12:03 am
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. :?

Re: Dynamic menu choices from array/list

Posted: Thu Feb 21, 2019 1:16 pm
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