21
Anonymous
Re: Milliseconds in flashgames
  • 2009/1/14 21:09

  • Anonymous

  • Posts: 0

  • Since:


Hello,

After play with some game, the score at MySQL is 43.42 and at flashgame page is 00:00:43

Note: Type of Score field is double


22
Anonymous
Re: Milliseconds in flashgames
  • 2009/1/15 0:46

  • Anonymous

  • Posts: 0

  • Since:


How I can use this example with $score ?

<?php
function udate($format, $utimestamp = null)
{
if (is_null($utimestamp))
$utimestamp = microtime(true);

$timestamp = floor($utimestamp);
$milliseconds = round(($utimestamp - $timestamp) * 1000000);

return date(preg_replace('`(?<!\\\\)u`', $milliseconds, $format), $timestamp);
}

echo udate('H:i:s.u'); // 19:40:56.78128
echo udate('H:i:s.u', 654532123.04546); // 16:28:43.45460
?>

23
Anonymous
Re: Milliseconds in flashgames
  • 2009/1/15 1:06

  • Anonymous

  • Posts: 0

  • Since:


Other example:

<?php

function timeAndMilliseconds()
{
$m = explode(' ',microtime());
return array($m[1], (int)round($m[0]*1000,3));
}

list($totalSeconds, $extraMilliseconds) = timeAndMilliseconds();
echo date("d-m-Y H:i:s", $totalSeconds) . ".$extraMillisecondsn";

?>

Output:
20-11-2005 23:28:19.500



24
ghia
Re: Milliseconds in flashgames
  • 2009/1/15 1:34

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Quote:
Note: Type of Score field is double
Yes, that is in the database. But the point here is how the Flash game transfers its score to XOOPS.
From what I see in the source:
if($gameInfo['gameType'] == '3' || $gameInfo['gameType'] == '4'){
        
//This game uses a time based scoring method
        
if(strstr($score":") !== false){

If the gametype is 3 or 4, then there is a time based score. And that can be transferred as a number or a string, which is tested by the strstr, which looks out for a colon ( : ). The following formating and decoding is done to cope with things like 0:1:2 .
But there is still no answer if there are only seconds passed in this variable $score or also divisions of it.

25
Anonymous
Re: Milliseconds in flashgames
  • 2009/1/15 5:31

  • Anonymous

  • Posts: 0

  • Since:


Time format of flashe game is 00:00:00.00

So if game time is 40seconds and 10milliseconds, it will save in db as 40.10 and at scores table will show as 00:00:40

I need to extend it to show milliseconds too.




26
ghia
Re: Milliseconds in flashgames
  • 2009/1/15 18:29

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Try with:
list($hour$min$sec$msec) = split('[:.,]'$score);
$score = ((($hour 60) + $min) * 60) + $sec;
if (
$msec 0)
{
  
$score += ($msec 1000.);
}


27
Anonymous
Re: Milliseconds in flashgames
  • 2009/1/15 20:32

  • Anonymous

  • Posts: 0

  • Since:


not working :(

I think these lines in flashgames/game.php may be cause the problem:
while($row1 $xoopsDB->fetchArray($result))
{
$score $row1['score'] ;    
if ( 
$gametype == 3  or  $gametype == ) {
 
//This is a time based score, so format it accordingly.  All time based scores are stored in seconds
 
$timestamp mktime(00$score);
 
$score strftime("%H:%M:%S"$timestamp);
 }
}





28
Anonymous
Re: Milliseconds in flashgames
  • 2009/1/16 2:45

  • Anonymous

  • Posts: 0

  • Since:


ok .. I added this line to game.php

The value of score at db is 45.34
The value of score at highscore table is 162000

Resized Image

29
ghia
Re: Milliseconds in flashgames
  • 2009/1/18 3:39

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Quote:
ok .. I added this line to game.php
Not sure to which line you are referring to.

Try with:
if ( $gametype == 3  or  $gametype == ) {
 
//This is a time based score, so format it accordingly.  All time based scores are stored in seconds
 
$score intval(intval($score)/3600).':'.bcmod((intval($score)/60),60).':'.bcmod($score,60);
 }

30
Anonymous
Re: Milliseconds in flashgames
  • 2009/1/27 1:06

  • Anonymous

  • Posts: 0

  • Since:


Finally trabis can fix it

if ( $gametype == 3 or $gametype == 4 ) {
//This is a time based score, so format it accordingly. All time based scores are stored in seconds
$timestamp = mktime(0, 0, $score);
$miliseconds = ($score - intval($score)) * 100;
if ($miliseconds < 10) $miliseconds = "0".$miliseconds;
$score = strftime("%H:%M:%S", $timestamp).".".$miliseconds;
}

Obrigado tabis

Login

Who's Online

90 user(s) are online (57 user(s) are browsing Support Forums)


Members: 0


Guests: 90


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits