Math Question: 1 million...
by Nicolai Dutka · in Torque Game Builder · 06/03/2008 (10:52 pm) · 7 replies
So I was play testing my game today and for the first time, I got over 1 million points. Well, as soon as I did, my score changed to this:
1.0155e+006
So, how can I fix that so my score can support higher numbers?
My score code:
Oh yeah, I am using a GuiMLTextCtrl to display the numbers. If I echo the score to console, it displayes there properly, just not in my GuiMLTextCtrl.
Ideas?
1.0155e+006
So, how can I fix that so my score can support higher numbers?
My score code:
$p1score+=500;
p1score.setText("<font:arial bold:30><color:ffffff><shadow:2:2><just:center>"@ $p1score);Oh yeah, I am using a GuiMLTextCtrl to display the numbers. If I echo the score to console, it displayes there properly, just not in my GuiMLTextCtrl.
Ideas?
#2
06/04/2008 (4:18 pm)
I guess I could work that into my code somewhere but if someone has a better solution, I would love to hear it.
#3
06/06/2008 (4:29 pm)
Anyone?
#4
06/06/2008 (4:48 pm)
How about converting the integer to a string and displaying that? How would I do the conversion with TorqueScript?
#5
The first displays correctly because it is basically just a string, nice and simple. If you look at the decimal points in the second example, you will notice that they are missing three numbers 7, 8 and 9 (the 6 was rounded up to 7) . This means that if you're using *very* large numbers, it is impossible (at least not with the method I am using) to take a number notated scientifically and transform it into an int.
The code below will format your number well enough, but it suffers the problem of dropping some of those low order numbers off the end.
Example:
06/06/2008 (5:22 pm)
Your problem is a bit bigger than you think Nicolai. Firstly, please note that TorqueScript variables are considered "strings" for all intensive purposes. When Torque adds two numbers to form a really large number it converts it to scientific notation and drops some of the lower numbers away. For example:// Result: 123456789 echo (123456789); // Result: 2.23457e+008 echo (100000000 + 123456789);
The first displays correctly because it is basically just a string, nice and simple. If you look at the decimal points in the second example, you will notice that they are missing three numbers 7, 8 and 9 (the 6 was rounded up to 7) . This means that if you're using *very* large numbers, it is impossible (at least not with the method I am using) to take a number notated scientifically and transform it into an int.
The code below will format your number well enough, but it suffers the problem of dropping some of those low order numbers off the end.
function makeInt(%number)
{
// If the number is in scientific format we want to display it as an int
if (getSubStr(%number, strlen(%number) - 4, 1) $= "+")
{
// Grab the decimal point's position
%dec = strpos(%number, ".");
// Grab the number to the left of the DP
%pre = getSubStr(%number, 0, %dec);
// Grab the number to the right of the DP
%pos = getSubStr(%number, %dec + 1, strlen(%number) - 7);
// Pad out the right hand number
%dp = getSubStr(%number, strlen(%number) - 3, 3);
while (strlen(%pos) != %dp)
%pos = %pos @ "0";
// Return the new string
return %pre @ %pos;
}
return %number;
}Example:
// Result: 223457000 echo (makeInt(100000000 + 123456789));
#6
%score = $p1score/100;
p1score.setText(%score @ "00");
That works for me because all the points in my game are tallied 500 or 1000 at a time, so the 10's and 1's are ALWAYS going to be 0.
Once I reach 100 million, I will be faced with the same problem, but again, in my game this is a non-issue because you typically have the game finished before ever reaching 2 million.
06/06/2008 (5:24 pm)
I came up with a basic solution for me, but it does not direct this math problem at all, but instead it circumvents it:%score = $p1score/100;
p1score.setText(%score @ "00");
That works for me because all the points in my game are tallied 500 or 1000 at a time, so the 10's and 1's are ALWAYS going to be 0.
Once I reach 100 million, I will be faced with the same problem, but again, in my game this is a non-issue because you typically have the game finished before ever reaching 2 million.
Torque Owner Brian Wilson
var1 < 100000
var2 => 100000
so;
var1 = 015500;
var2 = 10;
score = var2@var1;
But don't listen to me, there's a proper way to do this in the engine, I'm just reminiscing ;p