Using objects/classes and screens[SOLVED]
Posted: Mon Aug 21, 2017 10:34 am
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