Your own error

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
a7s1h1
Prole
Posts: 12
Joined: Sat May 25, 2013 2:15 pm

Your own error

Post by a7s1h1 »

Is there any way to crash the game with an error manually (with your own error message text)?
I mean something like that:
if a==0 then
<game crashes and the error message appears with the text "Error! a=0">
end

This can be useful to check the code during running the game.
So is that possible?
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Your own error

Post by micha »

You can use the commands error and assert. See in PiL.
a7s1h1
Prole
Posts: 12
Joined: Sat May 25, 2013 2:15 pm

Re: Your own error

Post by a7s1h1 »

micha wrote:You can use the commands error and assert. See in PiL.
Thanks, that's exactly what I need!
One more question. When an error appears, can I somehow write the text of the error to the error log file (error**.txt, where ** is a consecutive number of a file)?
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Your own error

Post by micha »

As far as I know, there is no standard functionality for this. You have to implement this on your own using love.filesystem. Note, however, that LÖVE only has writing access to your game's save directory.

If you are in Linux you can forward the error messages from the console to a textfile using this command:

Code: Select all

love . 2> error.txt
This will overwrite the error.txt each time.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Your own error

Post by Robin »

micha wrote:If you are in Linux you can forward the error messages from the console to a textfile using this command:

Code: Select all

love . 2> error.txt
This will overwrite the error.txt each time.
You can do that in Windows and OS X as well. You need to run your game in a terminal window (CMD.EXE on Windows), but the same goes for Linux.
Help us help you: attach a .love.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Your own error

Post by T-Bone »

Rather than running from a terminal/console, I'd say save yourself some trouble and run it from a script. They can also be distributed in case you want the end user to be able to make logs.
Post Reply

Who is online

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