notepad ++ code glitch. 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
User avatar
BEANSFTW
Prole
Posts: 28
Joined: Sun Apr 15, 2012 2:58 pm

notepad ++ code glitch. Help?

Post by BEANSFTW »

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
User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: notepad ++ code glitch. Help?

Post by qaisjp »

i dont quite understand what you're saying.
Lua is not an acronym.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: notepad ++ code glitch. Help?

Post by T-Bone »

Image

Looks fine for me. I'm using version 6.3.2.
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: notepad ++ code glitch. Help?

Post by slime »

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

Re: notepad ++ code glitch. Help?

Post by Robin »

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++.
Help us help you: attach a .love.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: notepad ++ code glitch. Help?

Post by Azhukar »

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

Re: notepad ++ code glitch. Help?

Post by sutao80216 »

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 ")"
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests