attribute error object has no attribute main

i was following this tutorial https://www.youtube.com/watch?v=-LQqOPY-N8I#t=191 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.camera = 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._selectObjects()
        else:
            self._dispatchSelected()
        self.scene.post_draw.pop()
        self.main = self._idle
        
# Facilitating methods

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

def _selectObjects(self):
    
    quad = self._getScreenQuad()
    
    self.selected = []
    
    for obj in self.scene.objects:
        if "gravity" in obj:
            obj.deselect()
            point = Vector(self.camera.getScreenPosition(obj.worldPosition))
            test = [point] + quad
            in_quad = geometry.intersect_point_quad_2d(*test)
            if in_quad:
                hit_obj = self.camera.getScreenRay(point.x, point.y, 1000)
                if hit_obj == obj:
                    obj.select()
                    self.selected.append(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.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, 1, 1, 0)
    
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    
    bgl.glColor3f(1, 0, 0)
    bgl.glBegin(bgl.GL_LINE_LOOP)
    for p in quad:
        bgl.glVertex2f(p.x, p.y)
    bgl.glEnd()

def main(cont):

own = cont.owner

if not "init" in own:
    own["init"] = 1
    Selector(own)
else:
    own.main()

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.