Page 1 of 1

Function Help.

Posted: Mon Feb 02, 2015 5:08 pm
by Schtekarn
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)"?

Re: Function Help.

Posted: Mon Feb 02, 2015 9:43 pm
by Robin
Well if you define bullet somewhere that should work. Could you please upload a .love? That way I'm sure we can help you out in 10 seconds flat.

Re: Function Help.

Posted: Tue Feb 03, 2015 10:58 am
by DaedalusYoung
End your bullet.lua file with

Code: Select all

return bullet
and then in main.lua do

Code: Select all

local bullet = require 'bullet'

Re: Function Help.

Posted: Tue Feb 03, 2015 2:00 pm
by Tjakka5
At the top of your bullet file type:
bullet = {}

Re: Function Help.

Posted: Tue Feb 03, 2015 6:58 pm
by Schtekarn
This was a weird bug but when I ran the program on a second computer it "Magically" worked for no clear reason what so ever so I'm calling this one solved and continue working on the other computer.