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.
-
JackDoe
- Newbie
- Posts: 15
- Joined: Sun Aug 12, 2018 10:28 am
-
Contact:
#1
Post
by JackDoe » Wed Feb 20, 2019 10:21 am
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.
-
Alex
- Lemma-Class Veteran
- Posts: 2981
- Joined: Fri Dec 11, 2009 5:25 pm
-
Contact:
#2
Post
by Alex » Wed Feb 20, 2019 11:44 am
-
JackDoe
- Newbie
- Posts: 15
- Joined: Sun Aug 12, 2018 10:28 am
-
Contact:
#3
Post
by JackDoe » Wed Feb 20, 2019 11:51 am
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
-
Alex
- Lemma-Class Veteran
- Posts: 2981
- Joined: Fri Dec 11, 2009 5:25 pm
-
Contact:
#4
Post
by Alex » 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.
-
JackDoe
- Newbie
- Posts: 15
- Joined: Sun Aug 12, 2018 10:28 am
-
Contact:
#5
Post
by JackDoe » Thu Feb 21, 2019 12:03 am
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.

-
Alex
- Lemma-Class Veteran
- Posts: 2981
- Joined: Fri Dec 11, 2009 5:25 pm
-
Contact:
#6
Post
by Alex » Thu Feb 21, 2019 1:16 pm
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
Users browsing this forum: No registered users