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 .
BEANSFTW
Prole
Posts: 28 Joined: Sun Apr 15, 2012 2:58 pm
Post
by BEANSFTW » Sat Jun 08, 2013 2:43 am
Paste this in notepad++. Not sure what happens, but on my computer, all the functions connect into one big function. Can anyone tell me whats wrong, or am i using an outdated version of notepad++?
Code: Select all
bullet_speed = 60
testBullet = {}
testB = love.graphics.newImage("pics"/"Bullets"/"testBullet.png")
function testBullet.spawn(x, y, dir)
tabe.insert(testBullet, {x = x, y = y, dir = dir}
end
function testBullet.draw()
for i,v in ipairs do
love.graphics.draw(testB, v.x, v.y)
end
end
function testBullet.update(dt)
if v.dir == "right" then
v.x = v.x + bullet_speed * dt
end
end
function testBullet.shoot(key)
if key == "right" then
testBullet.spawn(player.x + player.width, player.y + player.height / 2, "right")
end
end
qaisjp
Party member
Posts: 490 Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:
Post
by qaisjp » Sat Jun 08, 2013 3:05 am
i dont quite understand what you're saying.
Lua is not an acronym.
T-Bone
Inner party member
Posts: 1492 Joined: Thu Jun 09, 2011 9:03 am
Post
by T-Bone » Sat Jun 08, 2013 4:36 am
Looks fine for me. I'm using version 6.3.2.
slime
Solid Snayke
Posts: 3162 Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:
Post
by slime » Sat Jun 08, 2013 4:42 am
About the code itself:
Code: Select all
function testBullet.draw()
for i,v in ipairs do
love.graphics.draw(testB, v.x, v.y)
end
end
This should be:
Code: Select all
function testBullet.draw()
for i,v in ipairs(testBullet) do
love.graphics.draw(testB, v.x, v.y)
end
end
Or maybe:
Code: Select all
function testBullet:draw()
for i,v in ipairs(self) do
love.graphics.draw(testB, v.x, v.y)
end
end
(Make sure to call testBullet:draw() instead of testBullet.draw() with the last one.)
Same with this one:
Code: Select all
function testBullet.update(dt)
if v.dir == "right" then
v.x = v.x + bullet_speed * dt
end
end
It's missing a section of its code. It should be something like this:
Code: Select all
function testBullet.update(dt)
for i,v in ipairs(testBullet) do
if v.dir == "right" then
v.x = v.x + bullet_speed * dt
end
end
end
Robin
The Omniscient
Posts: 6506 Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:
Post
by Robin » Sat Jun 08, 2013 11:07 am
Two things:
Code: Select all
testB = love.graphics.newImage("pics"/"Bullets"/"testBullet.png")
should be
Code: Select all
testB = love.graphics.newImage("pics/Bullets/testBullet.png")
and
Code: Select all
function testBullet.spawn(x, y, dir)
tabe.insert(testBullet, {x = x, y = y, dir = dir}
end
you were missing a closing paren there:
Code: Select all
function testBullet.spawn(x, y, dir)
tabe.insert(testBullet, {x = x, y = y, dir = dir})
end
The latter one was probably what confused NP++.
Azhukar
Party member
Posts: 478 Joined: Fri Oct 26, 2012 11:54 am
Post
by Azhukar » Sat Jun 08, 2013 11:08 am
As was said you have a few syntax errors and even missing letters, but the issue you described is caused by a missing bracket at this line:
Code: Select all
tabe.insert(testBullet, {x = x, y = y, dir = dir}
Also an example of a missing letter.
sutao80216
Prole
Posts: 1 Joined: Sun Apr 07, 2013 12:43 am
Post
by sutao80216 » Sun Jun 09, 2013 1:59 am
with
Code: Select all
function testBullet.spawn(x, y, dir)
[b]tabe.insert(testBullet, {x = x, y = y, dir = dir}[/b]
end
you had lost a ")"
Users browsing this forum: Google [Bot] and 5 guests