Page 1 of 1

Game closes as soon as it starts.

Posted: Thu May 15, 2014 6:16 pm
by Branch Greenwood
Hello, I have a problem with the game I am currently trying to make. More specifically I have a chunk of code that appears to cause a crash at startup. More specifically this chunk which is inside of love.update.

Code: Select all

--set apple
	if apple.spawned == false then
		--is apple.x on player?
		local x = 0
		while x == 0 do
			apple.x = love.math.random(0, (wWidth - apple.size))
			if (apple.x + apple.size) < player.x or apple.x > (player.x + player.size) then
				x = 1
			end
		end
		
		--is apple.y on player?
		local y = 0
		while y == 0 do 
			apple.y = love.math.random(0, (wHeight - apple.size))
			if (apple.y + apple.size) < player.y or apple.y > (player.y + player.size) then
			y = 1
			end
		end
		--apple has spawned
		apple.spawned = true
	end
What I want to do is choose a random coordinate for x and check if set position is on the player, if it is not then repeat the same for y and set the apple once things check out fine. I have sent the code to a friend of mine who has successfully executed it and played, I however could not. I tried running it using the 32-bit and 64-bit engines (love 0.9.1) to no avail. If it's of any relevance I'm running all of this on my Win7 x64 Virtual Machine on VirtualBox. I have attached the .love if you wish to check it out. Help will be greatly appreciated.

This is my first time posting on theses forums so my apologies if I haven't added something necessary for you to assist me, simply tell me and I will do my best to fill you in on the missing details.

Thanks in advance.

Re: Game closes as soon as it starts.

Posted: Thu May 15, 2014 6:32 pm
by micha
Hi and welcome to our forum.

I got this error message, when I ran the code:

Code: Select all

Error: Syntax error: main.lua:53: 'then' expected near '�'
The reason is that before the "<" there is an invisible character, that looks like a " " but it isn't. To make it run, remove this invisible character and replace it by a space.
Branch Greenwood wrote:This is my first time posting on theses forums so my apologies if I haven't added something necessary for you to assist me, simply tell me and I will do my best to fill you in on the missing details.
Don't worry. You provided all necessary information.

If next time the love game immediately closes on start up, try running it from a console. That way you get an error message as text output.

Re: Game closes as soon as it starts.

Posted: Thu May 15, 2014 6:46 pm
by Branch Greenwood
micha wrote:Hi and welcome to our forum.
If next time the love game immediately closes on start up, try running it from a console. That way you get an error message as text output.
Thanks a lot for the help. How do I run my game from a console?

Re: Game closes as soon as it starts.

Posted: Thu May 15, 2014 7:29 pm
by micha
Sorry, I don't know how to run from console in Windows, because I'm on linux. Hopefully somebody else can help out here.

Re: Game closes as soon as it starts.

Posted: Sat May 17, 2014 7:48 am
by Nixola
On Windows, you have to put a file called [wiki]conf.lua[/wiki] in the same folder as main.lua, setting the "console" property to true. On other OSes, you should call "love path/to/game/folder (or .love file)" in a terminal.