Submenu based on object array

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
Baita
Newbie
Posts: 1
Joined: Thu Feb 15, 2024 10:18 pm
Contact:

Submenu based on object array

#1 Post by Baita »

Hi! I'm trying to develop a combat system in which the player will be able to choose different moves to hit and enemy with. I want to make it so that the player chooses an attack and then it creates a submenu on what enemy to attack. I currently have a class containing the objects, aka, the enemies with their different stats and I'm adding those objects to an array. I want to then take that array of enemies and make it so that the submenu is created with the choices being the enemy names, below is the class/array and the menu/submenu. I can't quite get it to work.

init python:
class Enemy:
def __init__ (self, enemyName, enemy_image, hp, atk):
self.name = enemyName
self.image = enemy_image
self.hp = hp
self.atk = atk


thug = Enemy(name="Thug", enemy_image="characters/isuruki.png", hp=100, atk=10)
thief = Enemy(name="Thief", enemy_image="characters/isuruki.png", hp=100, atk=10)

listEnemies = []

listEnemies.append(thug)
listEnemies.append(thief)




menu optionsMenu (screen="optionsChoice"):
"Weak slap":
$ enemyChoices = renpy.display_menu(listEnemies.name.text)
"[enemyChoices]"
"Flail wildly":
call flail_wildly
"Random thing":
text "do something random"
"Random thing 2":
menu optionsAttackMenu (screen="optionsChoice"):
"2nd attack":
call weak_attack
"3rd attack":
call flail_wildly
"4th attack":
text "do something random"
"Back":
call optionsMenu

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Submenu based on object array

#2 Post by gas »

Write a screen on purpose. All your issues will be gone.
Menu are made for standard VNL branching, and quite limited.

Pseudocode:

Code: Select all

screen whatever():
    vbox:
        for x in listEnemies:
            $ name = x.name
            textbutton "[name]" action Return(x)
In your script

Code: Select all

call screen whatever
$ goon = _return
now "goon" is a reference to the object you picked. So, goon.name is the name of the enemy you picked.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

Post Reply

Who is online

Users browsing this forum: Sirifys-Al