Function Help.
Posted: Mon Feb 02, 2015 5:08 pm
So I've watched some tutorials etc but I keep running in to the same problem every time I try to call a function inside a function. For example:
bullet.lua
function bullet.update(dt)
for i,v in ipairs(bullet) do
if v.dir == "right" then
v.x = v.x + bullet_speed * dt
end
if v.dir == "left" then
v.x = v.x - bullet_speed * dt
end
end
end
------------------------
Main.lua:
require "bullet"
function love.update(dt)
bullet.update(dt)
end
It's an incomplete code and I'm well aware of that but why do I get the error "attempt to call field 'update' (a nil value)"?
bullet.lua
function bullet.update(dt)
for i,v in ipairs(bullet) do
if v.dir == "right" then
v.x = v.x + bullet_speed * dt
end
if v.dir == "left" then
v.x = v.x - bullet_speed * dt
end
end
end
------------------------
Main.lua:
require "bullet"
function love.update(dt)
bullet.update(dt)
end
It's an incomplete code and I'm well aware of that but why do I get the error "attempt to call field 'update' (a nil value)"?