List of class objects

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
Hoomst
Newbie
Posts: 10
Joined: Wed Jun 08, 2022 9:46 am
Contact:

List of class objects

#1 Post by Hoomst » Sat Sep 03, 2022 3:05 pm

I'd like to create a list of class objects. I intend to use that list to create imagebuttons with a for loop (for g in girls_list...).

I get the following error:
NameError: name 'mg' is not defined

How can I create a list of these class objects?

Code: Select all

class Girl(object):

        def __init__(self, character, name, psyche_max=100, energy_max=100, psyche_temp=100, energy_temp=100):

            self.c = character
            self.name = name
            self.psyche_max = psyche_max
            self.energy_max = energy_max
            self.psyche_temp = psyche_temp
            self.energy_temp = energy_temp

default mg = Girl(Character("Megan"), "Megan", psyche_max=100, energy_max=100, psyche_temp=100, energy_temp=100)
default rx = Girl(Character("Roxy"), "Roxy", psyche_max=100, energy_max=100, psyche_temp=100, energy_temp=100)
default mi = Girl(Character("Mia"), "Mia", psyche_max=100, energy_max=100, psyche_temp=100, energy_temp=100)
    
$ girls_list = [mg, rx, mi]

User avatar
laure44
Regular
Posts: 60
Joined: Mon Mar 08, 2021 10:55 pm
Projects: Arkan'sTower, Gemshine Lorelei!
Location: France
Contact:

Re: List of class objects

#2 Post by laure44 » Sat Sep 03, 2022 3:11 pm

You can use default/define as you already did for your objects

Code: Select all

default girls_list = [mg, rx, mi]

Hoomst
Newbie
Posts: 10
Joined: Wed Jun 08, 2022 9:46 am
Contact:

Re: List of class objects

#3 Post by Hoomst » Sat Sep 03, 2022 4:31 pm

That solved my problem. Thanks for the quick response!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot]