Dani jel
Dani jel

Reputation: 21

Getting an "unresolved reference" error

I keep getting an "unresolved reference" error even though I made a statement to it.

verb_dict = {"say": say, "examine": examine}

The error is after the examine:

def examine(noun):
    if noun in GameObject.objects:
        return GameObject.objects[noun].get_desc()
    else:
        return "There is no {}".format(noun)

Did I do something wrong when coding it?

I am also using pycharm community edition.

Upvotes: 0

Views: 298

Answers (2)

JanHak
JanHak

Reputation: 1735

I can't replicate your problem in PyCharm 2016.14 I run the following code with no issue:

class GameObject:
    class_name = ""
    objects = {}

    def __init__(self, name):
        self.name = name
        GameObject.objects[self.class_name] = self


def examine(noun):
    if noun in GameObject.objects:
        return GameObject.objects[noun].get_desc()
    else:
        return "There is no {}".format(noun)

print(examine('try'))

Output is

>>> There is no try

Upvotes: 1

Dani jel
Dani jel

Reputation: 21

This is the GameObject class. I don't see a problem in there.If you need more tell me.

class GameObject:
    class_name = ""
    desc = ""
    objects = {}
    def __init__(self, name):

        self.name = name
        GameObject.objects[self.class_name] = self

Upvotes: 0

Related Questions