Game closes as soon as it starts.

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
User avatar
Branch Greenwood
Prole
Posts: 2
Joined: Wed Apr 30, 2014 7:38 pm
Location: Canada
Contact:

Game closes as soon as it starts.

Post 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.
Attachments
learning project.love
(734 Bytes) Downloaded 54 times
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Game closes as soon as it starts.

Post 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.
User avatar
Branch Greenwood
Prole
Posts: 2
Joined: Wed Apr 30, 2014 7:38 pm
Location: Canada
Contact:

Re: Game closes as soon as it starts.

Post 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?
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Game closes as soon as it starts.

Post 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.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Game closes as soon as it starts.

Post 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.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

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