Page 1 of 1

notepad ++ code glitch. Help?

Posted: Sat Jun 08, 2013 2:43 am
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

Re: notepad ++ code glitch. Help?

Posted: Sat Jun 08, 2013 3:05 am
by qaisjp
i dont quite understand what you're saying.

Re: notepad ++ code glitch. Help?

Posted: Sat Jun 08, 2013 4:36 am
by T-Bone
Image

Looks fine for me. I'm using version 6.3.2.

Re: notepad ++ code glitch. Help?

Posted: Sat Jun 08, 2013 4:42 am
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

Re: notepad ++ code glitch. Help?

Posted: Sat Jun 08, 2013 11:07 am
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++.

Re: notepad ++ code glitch. Help?

Posted: Sat Jun 08, 2013 11:08 am
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.

Re: notepad ++ code glitch. Help?

Posted: Sun Jun 09, 2013 1:59 am
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 ")"