Page 1 of 1

Using objects/classes and screens[SOLVED]

Posted: Mon Aug 21, 2017 10:34 am
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

Re: Using objects/classes and screens

Posted: Mon Aug 21, 2017 5:28 pm
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

Re: Using objects/classes and screens

Posted: Mon Aug 21, 2017 8:05 pm
by trooper6
You should define all your variables using default outside of any block

Re: Using objects/classes and screens

Posted: Tue Aug 22, 2017 5:12 am
by TellerFarsight
*facepalm*
I was doing "init python -1:"
and don't worry trooper6, I remembered about defaults *finger clicks or something*