Function Help.

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.
Post Reply
Schtekarn
Prole
Posts: 2
Joined: Mon Feb 02, 2015 4:59 pm

Function Help.

Post 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)"?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Function Help.

Post 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.
Help us help you: attach a .love.
User avatar
DaedalusYoung
Party member
Posts: 407
Joined: Sun Jul 14, 2013 8:04 pm

Re: Function Help.

Post 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'
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Re: Function Help.

Post by Tjakka5 »

At the top of your bullet file type:
bullet = {}
Schtekarn
Prole
Posts: 2
Joined: Mon Feb 02, 2015 4:59 pm

Re: Function Help.

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 161 guests