Using middleclass

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Ertain
Citizen
Posts: 55
Joined: Fri Nov 19, 2010 9:38 pm
Location: Texas, U.S.A.

Re: Using middleclass

Post by Ertain »

Thank you, guys. I shall edit my little script accordingly.
*Looks through script*
The stuff you guys have told me seem to be found in the code (i.e. no editing). Here's the error.

Code: Select all

boot    [string "menus.lua"]:32: attempt to index local 'self' (a nil value)    stack traceback:
        [string "boot.lua"]:833: in function 'error_printer'
        [string "boot.lua"]:768: in function <[string "boot.lua"]:766>
        [string "menus.lua"]:32: in function 'showMenus'
        [string "menus.lua"]:26: in function 'initialize'
        [string "middleclass.lua"]:37: in function 'new'
        [string "main.lua"]:9: in function 'update'
        [string "boot.lua"]:307: in function <[string "boot.lua"]:295>
        [C]: in function 'xpcall'
        [string "boot.lua"]:840: in main chunk
This is from the code seen in this thread. All of the syntax and whatnot seem to be correct.
Booted, suited, and ready to get executed.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Using middleclass

Post by kikito »

The error is on menus.lua, line 32. Can you put that line here?
When I write def I mean function.
User avatar
Ertain
Citizen
Posts: 55
Joined: Fri Nov 19, 2010 9:38 pm
Location: Texas, U.S.A.

Re: Using middleclass

Post by Ertain »

Sure, here's the line:

Code: Select all

for i=1, #self.menu do
Booted, suited, and ready to get executed.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Using middleclass

Post by kikito »

I believe that the problem is not on that function's declaration, but on it's invocation.

It's probably this:

Code: Select all

function Game:initialize()
  super.initialize(self)
  self.menu = {}
  self.index = 1
  self.topMenu = "top"
  self.showMenus()
  self.drawMenus()
end
The last two lines are method invocations and should have colons instead of dots:

Code: Select all

  self:showMenus()
  self:drawMenus()
And this is exactly why I don't like the colons in the first place. You will make that mistake again and again.
When I write def I mean function.
User avatar
Ertain
Citizen
Posts: 55
Joined: Fri Nov 19, 2010 9:38 pm
Location: Texas, U.S.A.

Re: Using middleclass

Post by Ertain »

Sweet. Thanks kikito! ^^
*Tries new changes*
Works... For now. ;)
Booted, suited, and ready to get executed.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest