Jump to content




Java game division not working correctly


  • You cannot reply to this topic
7 replies to this topic

#1 DSlink2010

  • Members
  • 50 posts

Posted 27 February 2013 - 02:23 PM

The problem is that at line 72 in Display.java the division problem outputs "0.0" instead of between "0.001"-"1". So can anyone please help? All the classes are down there.
Classes
Display.java
Spoiler

Render3D.java
Spoiler

Render.java
Spoiler

Screen.java
Spoiler

Game.java
Spoiler


#2 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 27 February 2013 - 02:48 PM

er, this isnt really the forum >_>

#3 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 27 February 2013 - 02:59 PM

General: Ask anything and everything related to anything and everything (anything and everything excluded) :P

On-Topic: Pastebin please? I don't wanna count to line 72.

#4 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 27 February 2013 - 03:41 PM

I'm guessing this one:
 unprocessedSeconds += passedTime / 1000000000;

passedTime is a long, and 1000000000 is an int. Neither of them are float or double, so it truncates the result.


#5 DSlink2010

  • Members
  • 50 posts

Posted 28 February 2013 - 09:44 AM

View Postimmibis, on 27 February 2013 - 03:41 PM, said:

I'm guessing this one:
unprocessedSeconds += passedTime / 1000000000;

passedTime is a long, and 1000000000 is an int. Neither of them are float or double, so it truncates the result.
I'll try changing them to ints.
[EDIT] I changed it to a int and it still outputs 0 as the answer.

#6 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

Posted 28 February 2013 - 10:12 AM

You might want to post this on StackOverflow or similar if you haven't already done so, you're more likely to get it fixed.

#7 DSlink2010

  • Members
  • 50 posts

Posted 28 February 2013 - 11:20 AM

I looked on Stack Overflow, and it showed that someone had a FPS count malfunction, and the answer was to remove the fps counter, I did, it works now. Its fixed, it goes fast, so I changed the amount of incrementation that game.time gets. So can any staff lock this?

#8 Xtansia

  • Members
  • 492 posts
  • LocationNew Zealand

Posted 28 February 2013 - 03:22 PM

View PostDSlink2010, on 28 February 2013 - 09:44 AM, said:

View Postimmibis, on 27 February 2013 - 03:41 PM, said:

I'm guessing this one:
unprocessedSeconds += passedTime / 1000000000;

passedTime is a long, and 1000000000 is an int. Neither of them are float or double, so it truncates the result.
I'll try changing them to ints.
[EDIT] I changed it to a int and it still outputs 0 as the answer.
They already were ints/longs,
He was meaning that either passedTime or 1000000000 needs to be a float or double for the division to work 'correctly'.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users