Creating classes? [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
enthrvlling
Newbie
Posts: 2
Joined: Mon Jul 10, 2017 9:40 am
Contact:

Creating classes? [SOLVED]

#1 Post by enthrvlling »

Hi, I'm pretty new to Python, so I'm sorry if this may seem like a dumb question.

I want to create a custom class for each character so I can keep track of certain attributes. How would I go about doing that? This was my first guess, but I know it's not right.

Code: Select all

class person:
    rank = 0
    backstory = 0
    festival = 0
Thank you for your time.
Last edited by enthrvlling on Mon Jul 10, 2017 11:33 am, edited 1 time in total.

User avatar
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

Re: Creating classes?

#2 Post by DannyGMaster »

In Ren'Py classes are defined like this:

Code: Select all

python:
    class Person:
        def __init__(self, rank=0, backstory=0, festival=0):
            self.rank = rank
            self.backstory = backstory
            self.festival = festival

default Sam = Person(rank=1) #The rest of arguments are assigned by default

label start:

    "Sam is Rank [Sam.rank]." 
You may want to check this new tutorial here for a deeper and better explanation of how classes work: viewtopic.php?f=51&t=44730
The silent voice within one's heart whispers the most profound wisdom.

User avatar
Evildumdum
Regular
Posts: 191
Joined: Sun Jan 18, 2015 8:49 am
Projects: ApoclypseZ
Contact:

Re: Creating classes?

#3 Post by Evildumdum »

Try watching this before you continue.

https://www.youtube.com/watch?v=trOZBgZ8F_c
"If at first you don't succeed, try hitting it with a shoe."

enthrvlling
Newbie
Posts: 2
Joined: Mon Jul 10, 2017 9:40 am
Contact:

Re: Creating classes? [SOLVED]

#4 Post by enthrvlling »

Thanks, all. I figured it out.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot