Noob here.

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.
Millow
Prole
Posts: 4
Joined: Thu Dec 03, 2009 6:31 am

Noob here.

Post by Millow »

Iv'e been messing with love/lua for about 3 days now, and I've hit a snag while trying to make a simple side scrolling beat'em up. I get the error, main.lua: 43: '}' expected (to close'{' at line 2 'draw', and can't seem to figure out what the problem is.

Here is line 43, draw, I know it's probably some of the worst coding you have ever seen, so feel free to point out any other issues. I'm just trying to grasp this programming thing.
draw = function(self)
if self.facing == 1 then }
if self.y <= 480 then self.vspeed = self.vspeed + self.gravity else
love.graphics.draw(self.walking_right, self.x, self.y)
else if
love.graphics.draw(self.falling_right, self.x, self.y)
end
else if self.facing == -1 then
if self.y <= 480 then self.vspeed = self.vspeed + self.gravity else
love.graphics.draw(self.walking_left, self.x, self.y)
else if
love.graphics.draw(sellf, self.x, self.y)
end
else if love.graphics.draw(self.falling_left, self.x, self.y)

end
end
}
User avatar
subrime
Citizen
Posts: 76
Joined: Thu Nov 13, 2008 6:18 pm
Location: Australia

Re: Noob here.

Post by subrime »

There are 3 problems:

(1) curly braces
You have scattered some curly braces in there... lua does not use them like c.

So try changing:
if self.facing == 1 then }
into:
if self.facing == 1 then

and remove the final } at the end.

(2) basic structure
The if keyword can be used in the following ways:

Code: Select all

-- one case
if test then
  -- do something
end

-- two cases
if test then
  -- do something
else
  -- do something else
end

-- many cases
if test1 then
  -- do something
elseif test2 then
  -- do something else
elseif test3 then
  -- and so on
else
  -- getting the idea?
end
(3) spelling
You also have a typo:
love.graphics.draw(sellf, self.x, self.y)
Look carefully at the first argument (sellf)

It looks like you might get some benefit from going over basic lua docs.
Millow
Prole
Posts: 4
Joined: Thu Dec 03, 2009 6:31 am

Re: Noob here.

Post by Millow »

Thanks for the reply.
I guess I probably should read the docs..... :death:
Millow
Prole
Posts: 4
Joined: Thu Dec 03, 2009 6:31 am

Re: Noob here.

Post by Millow »

What dose, Error in update (arg 2), expected 'float' got nil mean?
function update(self,dt)

if love.keyboard.isDown(love.key_d) then
x = x + (speed * dt)
self.facing = 1
elseif love.keyboard.isDown(love.key_a) then
x = x - (speed * dt)
self.facing = 2
else
facing = 0
end

if love.keyboard.isDown(love.key_s) then
y = y + (speed * dt)
elseif love.keyboard.isDown(love.key_w) then
y = y - (speed * dt)
end

leftanime:update(dt)
rightanime:update(dt)

end
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Noob here.

Post by kikito »

The error is here:

Code: Select all

function update(self, dt)
The error says: Error in update (arg 2), expected 'float' got nil - this means that "in the update function (that accepts two parameters) I was expecting a float value, but I got a nil value instead"

This happens because the 'self' parameter is an undefined (nil) variable. update() only needs one parameter (dt). Try removing self so it looks like this:

Code: Select all

function update(dt)
And see how it goes.
When I write def I mean function.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Noob here.

Post by Robin »

Actually, ;)

dt is nil here. Because:

Code: Select all

function test(a, b)
    print("a is", a, "b is", b)
end

test(0.1) -- prints: a is 0.1     b is nil
update() is called with one argument, which we usually call dt. If you define more arguments, only the first will contain that value, the rest will be nil. And if a value is nil, you can't do arithmetics with it.

The solution kikito gave is correct, though.
Help us help you: attach a .love.
Millow
Prole
Posts: 4
Joined: Thu Dec 03, 2009 6:31 am

Re: Noob here.

Post by Millow »

Thanks! I removed it and it compiled, :rofl:
User avatar
osgeld
Party member
Posts: 303
Joined: Sun Nov 23, 2008 10:13 pm

Re: Noob here.

Post by osgeld »

you could use curly braces in lua, it usually ignores them, but you have to have propper {} pairs for that to work
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Noob here.

Post by Robin »

osgeld wrote:you could use curly braces in lua, it usually ignores them, but you have to have propper {} pairs for that to work
Not in standard Lua you can't. Syntax error.
Help us help you: attach a .love.
User avatar
osgeld
Party member
Posts: 303
Joined: Sun Nov 23, 2008 10:13 pm

Re: Noob here.

Post by osgeld »

well poop!

I remember it working somewhere in lua, maybe some aicent version, not that i ever really tried
Post Reply

Who is online

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