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)"?
Function Help.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Function Help.
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.
Help us help you: attach a .love.
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: Function Help.
End your bullet.lua file with
and then in main.lua do
Code: Select all
return bullet
Code: Select all
local bullet = require 'bullet'
Re: Function Help.
At the top of your bullet file type:
bullet = {}
bullet = {}
Re: Function Help.
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.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests