Page 1 of 1

[SOLVED] Error: Attempt to call upvalue (a nil value)

Posted: Thu Aug 17, 2017 8:32 pm
by fairenough
Hi all! I'm back with another question.

So I'm using hump's class system, and everything is going swimmingly so far. Or was, until I added another class. Which to me means I screwed something up in the code for the new class. I've made classes before and it went fine, which has me pulling my hair out trying to figure this one out.

When I launch the game, I get:
gamestates/gameLevel1.lua:19: attempt to call upvalue 'Explosion' (a nil value)

Here's the code for gameLevel1.lua:
(line 19 is: exp = Explosion(0,0) as you may have guessed)

Code: Select all

Gamestate = require 'libs.hump.gamestate'

local Entities = require 'entities.Entities'
local Entity = require 'entities.Entity'

local gameLevel1 = {}


local Player = require 'entities.player'
local Bg = require 'entities.background'
local Enemy = require 'entities.enemy'
local Explosion require 'entities.explosion'

function gameLevel1:enter()
  Entities:enter()
  background = Bg(0,0)
  enemy = Enemy(200,200)
  exp = Explosion(0,0)
  
  player = Player(100, 50, exp)
  Entities:addMany({background, exp, player, enemy})
end

function gameLevel1:update(dt)
  Entities:update(dt)
end

function gameLevel1:draw()
  Entities:draw()
end

return gameLevel1
And for kicks, here's explosion.lua (which to the best of my knowledge is a duplicate of the other classes I've made):

Code: Select all

local Class = require 'libs.hump.class'
local Entity = require 'entities.Entity'

local explosion = Class{
  __includes = Entity
}


function explosion:init(x, y)
  local img = love.graphics.newImage("assets/explosion04.png")
  self.explosion = love.graphics.newParticleSystem(img, 32)
  self.explosion:setParticleLifetime(1,2)
  self.explosion:setSpeed(50,75)
  self.explosion:setRotation(0,3)
  self.explosion:setSizes(0.01,0.05)
  self.explosion:setColors(255,255,255,255,255,255,255,0)
--  self.explosion:setDirection(3)
  self.explosion:setParticleLifetime( 0.25, 0.5 )
  
  -- Init Class
  Entity.init(self, x, y, 1,1)
end


function explosion:update(dt)
  self.explosion:update(dt)
end


function explosion:boom(x,y)
  self.explosion:moveTo(x,y)
  self.explosion:emit(10)
end

function explosion:draw()
  love.graphics.draw(self.explosion)
end


return explosion
I've also attached the .love file. Any insight would be very appreciated! Thank you!

Re: Error: Attempt to call upvalue (a nil value)

Posted: Thu Aug 17, 2017 9:24 pm
by Ref

Code: Select all

local Explosion require 'entities.explosion'
No '=' so no Explosion

Re: Error: Attempt to call upvalue (a nil value)

Posted: Fri Aug 18, 2017 12:45 am
by fairenough
OMFG.

Jesus. So simple. I *knew* it was going to be something simple.

Thank you. *puts head down in shame and shuffles away* :)