When i try to close my game, it almost crashes. I think my code has some problems, but maybe you could check it out?
Thanks!
PS: I cant figure out how to reload using a timer, so i would be GLAD if you could fix that for me.
Game crashes when closing
Game crashes when closing
- Attachments
-
- TOTAL Shootout.love
- (102.63 KiB) Downloaded 97 times
I can't come up with a good signature!
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Game crashes when closing
I can't see where the problem lies. I can, however, see some other problems:
- math.random() should only be called once, at the top of the screen.
- Do not use that sleep function. It stops the whole game, which is not good. You should rewrite it to how you did it with randomisetargetPos.
- Not so much a problem, but "if shootable == true then" is redundant. Since shootable is boolean, you can just use "if shootable then".
Help us help you: attach a .love.
Re: Game crashes when closing
Create all your fonts at the loading stage. You're wasting a lot of time and memory if you do it on every update. (main.lua line 57)
Make sure you always pass a font object to love.graphics.setFont in the update and draw functions.
Make sure you always pass a font object to love.graphics.setFont in the update and draw functions.
Shallow indentations.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Game crashes when closing
Let me tell you something about love.graphics.setFont(number)
It's just a matter of time.
It's just a matter of time.
When I write def I mean function.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Game crashes when closing
What? Why? Don't tell it's just because it takes a bit for beginners to understand what's really going on.kikito wrote:Let me tell you something about love.graphics.setFont(number)
It's just a matter of time.
Re: Game crashes when closing
Well, the function is called setFont and not setAndCreateFont. It delivers more than it should!BlackBulletIV wrote:What? Why? Don't tell it's just because it takes a bit for beginners to understand what's really going on.
I told bartbes once that this makes it easier to fall into this trap and he said: "yes, but it's so much more convenient".
Maybe a bigger warning on the wiki might help.
Shallow indentations.
Re: Game crashes when closing
But wait, Robin? How can i make it loop for only the time of the reload? I know, i suck at it. But im still a beginner
I can't come up with a good signature!
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Game crashes when closing
Let's see.BlackBulletIV wrote:What? Why? Don't tell it's just because it takes a bit for beginners to understand what's really going on.
Code: Select all
love.graphics.setFont(love.graphics.newFont(2))
-- vs
love.graphics.setFont(2)
- 23 characters less (assuming that you don't assign love.graphics to a local variable and make it shorter). This is the "convenience" bit.
- Some tutorials use setFont(number), and that would have to be changed
- This is not the first time someone has used it incorrectly. In the forum I've seen 10 or so - I can only wonder how many undetected memory leaking samples are there. This number can only increase, until something changes. Each of the threads is way more tan 23 characters long.
- Misleading name (setFont when in reality it's createAndSetFont)
- Resource loading coupled with drawing aspects in one function. We have recently had a discussion about why having love.draw separated from love.update is a good idea. Well, love.graphics.setFont(n) has one feet in love.load and the other one in love.draw. Doesn't that sound strange?
- Inconsistency. The other graphical "set" functions (i.e. love.graphics.setColor) can be called from inside love.draw; When someone sees a tutorial where love.setFont(n) is used in conjunction with love.graphics.setColor. A very natural step is trying to get multi-colored text by calling love.setColor several times inside love.draw. Well, another logical step is trying to call love.setFont(n) to have two different sizes of fonts. But that is wrong.
When I write def I mean function.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Game crashes when closing
Wouldn't a simpler / more convenient solution be to add a check in Love itself to see if the font already exists? We're not talking about something that should consume an inordinate amount of time, from a development or execution perspective, and it won't break old code while fixing the problem that keeps on cropping up.
Kurosuke needs beta testers
Who is online
Users browsing this forum: No registered users and 224 guests