Love2D second .lua file problem

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
pauls313
Citizen
Posts: 50
Joined: Tue Aug 02, 2016 3:07 am

Love2D second .lua file problem

Post by pauls313 »

I'm using a separate .lua file to handle physics. It basically runs through every solid file twice, to see if it has collided with any. But I think my main .lua file isn't loading the correct file. I always get the same error saying: "end expected to close for at line 2 in physics.lua". I deleted the "for" at line 2 and 3, but it keeps saying that there should be an end to close the (unexistent) for.

Code: Select all

 function physics(table)
for i,obj in ipairs(table) do
if obj.solid then
for i,newobj in ipairs(table) do
if (obj.y + obj.height + obj.yspeed) > newobj.y and (obj.x > newobj.x or (obj.x + obj.width) < (newobj.x + newobj.width)) then
obj.isGrounded = true
else
obj.isGrounded = false
end
end
if not(obj.isGrounded) then
obj.yspeed = obj.yspeed + gravity
end
end
end
end
end 
User avatar
whiteland92
Prole
Posts: 12
Joined: Fri Jul 04, 2014 1:30 am

Re: Love2D second .lua file problem

Post by whiteland92 »

if you indent your code it would be easier to spot what's wrong with it. you got one end too much.

Code: Select all

function physics(table)
	for i,obj in ipairs(table) do
		if obj.solid then
			for i,newobj in ipairs(table) do
				if (obj.y + obj.height + obj.yspeed) > newobj.y and (obj.x > newobj.x or (obj.x + obj.width) < (newobj.x + newobj.width)) then
					obj.isGrounded = true
					else
					obj.isGrounded = false
				end
			end
			if not(obj.isGrounded) then
				obj.yspeed = obj.yspeed + gravity
			end
		end
	end
end
end -- one end too much.
pauls313
Citizen
Posts: 50
Joined: Tue Aug 02, 2016 3:07 am

Re: Love2D second .lua file problem

Post by pauls313 »

Pretty sure that's not the problem

As I said, even if I delete the whole code I still get the same error. There must be a problem loading the file
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Love2D second .lua file problem

Post by zorg »

Well, wrap up your project into a .love file, and upload it here so we can see it and help you out. :3
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
pauls313
Citizen
Posts: 50
Joined: Tue Aug 02, 2016 3:07 am

Re: Love2D second .lua file problem

Post by pauls313 »

Sure, here
Attachments
lovegame.love
(709 Bytes) Downloaded 171 times
pauls313
Citizen
Posts: 50
Joined: Tue Aug 02, 2016 3:07 am

Re: Love2D second .lua file problem

Post by pauls313 »

Oh well, just realized what was wrong

The compiler said that there was a problem at physics.lua but it was at main.lua
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Love2D second .lua file problem

Post by MadByte »

As whiteland92 said, try to indent your code properly!
I found a couple of problems with your code.

#1 in your main:

Code: Select all

-- Is : --
function love.draw()
for i,obj in ipairs(objects) do
love.graphics.rectangle("fill",obj.x,obj.y,obj.width,obj.height)
end
  
-- Should be : --
function love.draw()
  for i,obj in ipairs(objects) do
    love.graphics.rectangle("fill",obj.x,obj.y,obj.width,obj.height)
  end
end
#2 physics.lua line 4:

Code: Select all

-- is: --
for i,newobj inipairs(table) do

-- should be: --
for i,newobj in ipairs(table) do
#3 one of your "objects" dont have a "height" variable which causes an error.

Before saying it must be a problem with loading a file you may want to search for mistakes on your end
(because it's about 99,99% your fault) ;)
Post Reply

Who is online

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