What do i do wrong?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
plz_m0ve
Prole
Posts: 16
Joined: Fri Jan 04, 2013 4:07 pm

What do i do wrong?

Post by plz_m0ve »

Hey, i got this strange error i dont know why happen

This is the code where the problem is:

Code: Select all

function love.draw()
-- Drawing some ground
love.graphics.setColor(255,0,0)
love.graphics.rectangle("fill", 0, 550, 800, 600)
end

-- Drawing the Hero ;D!
love.graphics.draw(hero, x, y)
love.graphics.setColor(250,0,0)
end

--Getting some text for the player to see
love.graphics.print("My first game :D!", 400, 300)
love.graphics.setColor(250,0,0)
end
And it all started when i addet setColor to the hero and a end on because i wanted it to have a different color than the rectangle that is the ground.
The same happend when i tried it with the text. So when i try to start my file, i get this:

Code: Select all

Error
Syntax error: main.lua:35: '<eof>' expected near 'end'

Traceback

[C]: ?
[C]: in function 'require'
[C]: in the function 'xpcall'
What do i do wrong? :)
LÖVE IS IN THE AIR
- OBEY
User avatar
Larsii30
Party member
Posts: 267
Joined: Sun Sep 11, 2011 9:36 am
Location: Germany

Re: What do i do wrong?

Post by Larsii30 »

An "end" is just used to end a loop.
Also you have to set the color of each object BEFORE you actually draw it .

Code: Select all

function love.draw()

-- Drawing some ground
love.graphics.setColor(255,0,0)
love.graphics.rectangle("fill", 0, 550, 800, 600)

-- Drawing the Hero ;D!
love.graphics.setColor(250,0,0)
love.graphics.draw(hero, x, y)

--Getting some text for the player to see
love.graphics.setColor(250,0,0)
love.graphics.print("My first game :D!", 400, 300)

end
You have to set the color before draw something because the loop start at the loop beginning and
read the information like you read a book. From up , down - from Left to right.

A tipp: The error message you get tells you where you did a fault and also tell you what you did wrong.
Try to use this to solve your problem on your own.

greets
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: What do i do wrong?

Post by substitute541 »

Let me explain about your error message for a bit.

Syntax errors mean exactly what they say; there's something wrong with the syntax of your code, in this case, putting "end"s at the wrong places. "end" is only used to end a function or a loop, not to end a statement or command.

<eof> means "end of file", as in, the end of your script or, the end of a file that you are reading.

Each error statement usually have this syntax :

Code: Select all

[Type of Error]: [File of which the error originated]:[Line number]: [Error message]
And there are also some things in the traceback that is important :

Code: Select all

Traceback

[File of which the error originated]: In function [Function of which the error originated] at line [Line number]
.
.
.
[C]: In function [the function that you called to produce the error, for example, you required a lua file with an error in it]
.
.
.
[C]: In function xpcall
And, please use tabbing (either pressing the tab key while typing in a code editor, or pressing 4 spaces) inside each function/loop/statement to clean up and make it easier to read. Example :

Code: Select all

-- Instead of
if collide(rectA, rectB) then
explodeObjects(rectA,rectB)
end

-- Do
if collide(rectA, rectB) then
    explodeObjects(rectA,rectB)
end
That's all.
Currently designing themes for WordPress.

Sometimes lurks around the forum.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests