Page 1 of 2

Error creating Hello World game

Posted: Thu Oct 28, 2010 5:42 pm
by patrickjcollins
Dear fellow lovers,

I'm straight out of the blocks, into the first hurdle and BAM!, I have fallen flat on my face. Been googling around, and searched this forum, can't find the solution to my problem.

I've downloaded and installed the latest version of Love for Mac (0.6.2). I can run the bundled demos. However, when I try and create and run my own game I'm seeing the following error :

syntax error: main.lua:2: unexpected symbol near 'Â'

This is the code that I copied from the wiki :

function love.draw()
love.graphics.print("Hello World", 400, 300)
end

To run the game, I'm dragging the folder that contains main.lua onto the Love icon.

I have tried creating the file with both TextEdit and TextWrangler. I suspect this problem may be due the text encoding used to save the file. In TextWrangler I have tried UTF8, UTF16, BOM and no BOM, and a wild variety of other settings in vain. I notice that the unexpected symbol in the error message changes when I change the encoding.

Any assistance would be greatly appreciated.

Patrick

Re: Error creating Hello World game

Posted: Thu Oct 28, 2010 7:09 pm
by Robin
Could you upload the exact file to the forums? It should work with UTF-8 without BOM, as that is backwards compatible with ASCII.

Re: Error creating Hello World game

Posted: Thu Oct 28, 2010 7:21 pm
by zac352
... I use GEdit. I [usually] save in a western encoding, because I have GEdit for windows, because I don't have the packages to use Love for Linux.

Re: Error creating Hello World game

Posted: Thu Oct 28, 2010 9:23 pm
by patrickjcollins
Here is a copy of the main.lua file, saved in UTF8.

Re: Error creating Hello World game

Posted: Thu Oct 28, 2010 9:30 pm
by TechnoCat
You are using an odd whitespace character on line 2.
Also, it looks like it starts with a BOM.

Re: Error creating Hello World game

Posted: Thu Oct 28, 2010 9:39 pm
by Robin
Your indentation uses weird characters: 0xc2 0xa0 (194 160 in decimal), which is a non-breaking space. You might need to tweak some settings to produce simple 0x20 (32) spaces. Or use a better text editor. ;)
TechnoCat wrote:Also, it looks like it starts with a BOM.
Now that I think of it, Lua handles BOM probably correctly.

Re: Error creating Hello World game

Posted: Thu Oct 28, 2010 9:47 pm
by TechnoCat
Robin wrote:Now that I think of it, Lua handles BOM probably correctly.
I had to remove the 3 bytes at the beginning and the bad whitespace to get it to run. BOM should be 4 bytes IIRC.

Re: Error creating Hello World game

Posted: Fri Oct 29, 2010 2:52 am
by Jasoco
If it's Windows, I hear NotePad++ is pretty good.

Re: Error creating Hello World game

Posted: Fri Oct 29, 2010 10:00 am
by patrickjcollins
Thanks chaps. To get it working I had to delete the spaces before "love.graphics.print" and save the file as UTF without BOM. Talk about a rocky start.

Re: Error creating Hello World game

Posted: Fri Oct 29, 2010 10:01 am
by nevon
patrickjcollins wrote:Thanks chaps. To get it working I had to delete the spaces before "love.graphics.print" and save the file as UTF without BOM. Talk about a rocky start.
I would suggest that you get a different text editor. Coding without whitespace really isn't an option.