Hello everyone,
I'm making good progress in my game, but now I've run into a problem:
https://dl.dropboxusercontent.com/u/218 ... eFrog.love
(press Enter and then D to get to the relevant screen)
My problem is in line 79 of main.lua. This line prints the maximum of either the seconds remaining, or 0. It works normally except when the expression resolves to 0. In that case, it prints it as -0. I have looked at this for a while and I can't find out what is going on. Please help!
Problem with math.max returning -0
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Problem with math.max returning -0
I'm not exactly sure whats going on, mainly because I only skimmed your code... Also couldn't run your game because the PC im on right now is old and doesn't support OpenGL. But I just want to touch on a few things:
main.lua(line 79):
I'm not sure why you are multiplying round_timer by min_dt. That would return a fraction of the actual time remaining.
main.lua(line 307):
You should multiply 1 by dt. As is, it will subtract 1/frame.
main.lua(line 418):
This one's nothing big, but I'm not sure if you missed the quotations between 20% and Wire Ocean.
I can take another proof-reading look later after work if you'd like, but like I said... For the time being I can't actually play the game to review it for you... Also you should look into GitHub so pointing things out are a little easier.![Wink ;)](./images/smilies/ms-wink.png)
EDIT **
Also to fix negative 0 you could just wrap it in a math.abs().
main.lua(line 79):
Code: Select all
love.graphics.printf(math.max(math.ceil(round_timer * min_dt), 0), 0, 6, screen.widthPx, "center")
main.lua(line 307):
Code: Select all
round_timer = round_timer - 1
main.lua(line 418):
Code: Select all
char_text = {
{"Hyper Jump", "Hyper Kick", "+40%", "Double Jump"},
{"Wire Sea", "Frog On Land", "+20%, Wire Ocean", "Dandy Frog (Wire Sea OK)\n—— Bunker (Wire Sea OK)"}
}
I can take another proof-reading look later after work if you'd like, but like I said... For the time being I can't actually play the game to review it for you... Also you should look into GitHub so pointing things out are a little easier.
![Wink ;)](./images/smilies/ms-wink.png)
EDIT **
Also to fix negative 0 you could just wrap it in a math.abs().
Re: Problem with math.max returning -0
math.abs(math.max...) should do the trick.
Edit: missed Beelz's edit, sorry.
Edit: missed Beelz's edit, sorry.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Problem with math.max returning -0
Yeah I don't know if -0 is really going to cause any problems since it's the same as absolute zero. So any math you'd be using would end up working the same. If it's a visual issue just math.abs the number before displaying like mentioned above. I literally just had to do this myself because the RGB values that were being returned by a HSL function I was using were being returned as decimals with a dozen places and negative zeroes in many cases. Weird. But I fixed it. setColor doesn't care as long as it's a number. But when presenting it to the eyes it looks silly.
Re: Problem with math.max returning -0
Yeah, there's a few rare cases where -0 makes a difference, apart form display. For example, math.atan2(0,-1) returns 3.1415926535898 but math.atan2(-0,-1) returns -3.1415926535898. But in general, it's nothing to worry about besides for display purposes. They compare as equal: assert(0==-0) doesn't err.
-
- Prole
- Posts: 34
- Joined: Sat Nov 28, 2015 5:54 am
Re: Problem with math.max returning -0
Thanks everyone. It's just a visual issue, since I'm displaying it with printf, -0 looks weird there. math.abs is great!
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 3 guests