Using objects/classes and screens[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
User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Using objects/classes and screens[SOLVED]

#1 Post by TellerFarsight »

I'm having a little trouble getting started on a battle framework. I have this bit of code but when I run it, it responds with "Marl is not defined." I've tried putting the definition statement in a one-line python statement, in the python block, in the label. I tried to mess around with initiation times but I can't get Marl to be defined. What am I missing here?

Code: Select all

python:
    from random import randint
    class Unit(object):
        def __init__(self,name,hp,attack,defense):
            self.name = name
            self.hp = hp
            self.attack = attack
            self.defense = defense
        def damage(self, enemy):
            damage = randint(1,self.attack) - enemy.defense
        
    Marl = Unit("Marl",100,3,1)  ## This is what defines it, right?

screen dudes():
    text "[Marl.hp]"
    
# The game starts here.

label start:

    # Show a background. This uses a placeholder by default, but you can
    # add a file (named either "bg room.png" or "bg room.jpg") to the
    # images directory to show it.

    scene bg room

    # This shows a character sprite. A placeholder is used, but you can
    # replace it by adding a file named "eileen happy.png" to the images
    # directory.

    show eileen happy

    # These display lines of dialogue.

    "Hello, world."
    
    show screen dudes
Last edited by TellerFarsight on Thu Aug 24, 2017 10:24 pm, edited 1 time in total.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Using objects/classes and screens

#2 Post by Remix »

init -1 python:
....# code

or maybe

python early:
....# code

the numeric, the -1 is basically a chronology for the inits, so you can set -1 occurs before 0 occurs before 1 etc
Frameworks & Scriptlets:

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Using objects/classes and screens

#3 Post by trooper6 »

You should define all your variables using default outside of any block
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Using objects/classes and screens

#4 Post by TellerFarsight »

*facepalm*
I was doing "init python -1:"
and don't worry trooper6, I remembered about defaults *finger clicks or something*
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

Post Reply

Who is online

Users browsing this forum: simple_human