attribute error object has no attribute main

i was following this tutorial when i ran into some problems. The error message it gave me is clear enough, but even when i imported the code from the .blend of the tutorial, i still received the same error. here is the code, the error is coming from the last line. (sorry the code lost its formatting, i cant figure out how to fix that, some help would be nice)

from bge import logic, types
from mathutils import Vector, geometry
import bgl

class Selector(types.KX_LightObject):

def __init__(self, own):
    #self.scene = logic.getCurrentScene() # defined by default in later blender versions = self.scene.objects["Camera"]
    cont = self.controllers[0]
    self.mouseclick = cont.sensors["mouseclick"]
    self.mouseover = cont.sensors["mouseover"]
    self.box_coords = [None, None]
    self.selected = []
    self.main = self._idle
# States

def _idle(self):
    if self.mouseclick.positive:
        self.box_coords[0] = logic.mouse.position
        self.main = self._select

def _select(self):
    self.box_coords[1] = logic.mouse.position
    self.scene.post_draw = [self._drawSelectionBox]
    if not self.mouseclick.positive:
        if self.box_coords[0] != self.box_coords[1]:
        self.main = self._idle
# Facilitating methods

def _dispatchSelected(self):
    if self.mouseover.positive:
        hit_pos = self.mouseover.hitPosition
        for obj in self.selected:

def _selectObjects(self):
    quad = self._getScreenQuad()
    self.selected = []
    for obj in self.scene.objects:
        if "gravity" in obj:
            point = Vector(
            test = [point] + quad
            in_quad = geometry.intersect_point_quad_2d(*test)
            if in_quad:
                hit_obj =, point.y, 1000)
                if hit_obj == obj:

def _getScreenQuad(self):
    vec_A = Vector(self.box_coords[0])
    vec_B = Vector(self.box_coords[1])
    delta = vec_B - vec_A
    vec_a = vec_A.copy()
    vec_a.x += delta.x
    vec_b = vec_B.copy()
    vec_b.x -= delta.x
    return [vec_A, vec_a, vec_B, vec_b]

def _drawSelectionBox(self):
    quad = self._getScreenQuad()
    bgl.gluOrtho2D(0, 1, 1, 0)
    bgl.glColor3f(1, 0, 0)
    for p in quad:
        bgl.glVertex2f(p.x, p.y)

def main(cont):

own = cont.owner

if not "init" in own:
    own["init"] = 1

It sounds like it is complaining that the Selector class does not have a method called ‘main’. When you call ‘own.main()’ that is telling Python to execute a method on the object.

um, okay, so how do i fix this? I already know that’s the problem, why does it work in his blend and not mine?

so… it works now? I closed blender, came back to it later, and it works! I changed nothing at all, so it must be a bug with bledner

Objects don’t have main() as an attribute. “own.main()” is telling Python to run a function called “main” that’s attached to the object, which doesn’t exist.

Something must have changed between when you closed/opened blender. Did you copy/paste the Selector code into your script? If so, are you sure that you didn’t miss copying the ‘main’ method?

Nope, i copied the main method 100%. My other scripts that i wrote myself had the same issue, but it went away too.