Jump to content

Milliseconds to seconds?


megaman54

Recommended Posts

Posted

Ahh, i dont really understand so i must make a example..

So its like this? :

function calcMsecs(player, command, mSecs) 
seconds = tonumber(mSecs) / 1000 
outputChatBox(seconds, player) 
end 
addCommandHandler("msecs", calcMsecs) 

Posted
function convertMSToSeconds ( MS ) 
local seconds = tonumber ( MS ) / 1000 
return seconds 
end 

What you did is correct too.

Posted

or

  
function MsToSeconds( MS ) 
local seconds = tonumber ( MS ) * 1000 
return seconds 
end 
  
setTimer( function, MsToSeconds( 50 ), 1 ) 
  

Posted
or
  
function MsToSeconds( MS ) 
local seconds = tonumber ( MS ) * 1000 
return seconds 
end 
  
setTimer( function, MsToSeconds( 50 ), 1 ) 
  

seriusly, wtf is that?

Posted
or
  
function MsToSeconds( MS ) 
local seconds = tonumber ( MS ) * 1000 
return seconds 
end 
  
setTimer( function, MsToSeconds( 50 ), 1 ) 
  

Wrong calculation, and setTimer arguments are wrong.

Posted

Then it should be:

SecondsToMS

And setTimer is still wrong.

should be:

function SecondsToMS( Seconds ) 
local MS = tonumber ( Seconds ) * 1000 
return MS 
end 
setTimer( function ( ) outputChatBox("test") end, SecondsToMS( 5) , 1 ) 

Posted

There is no need for new variable, simply return the results:

function ms2sec( ms ) 
    return ms / 1000; 
end 
  
function sec2ms( sec ) 
    return sec * 1000; 
end 

This is all simple maths.

  • MTA Team
Posted
Why would you even use a function for something simple like this? I'm going to nominate this topic as the longest for a too simple question of 2011 :|

I don't know.. maybe to prevent doing this:

(6000/1000)+(1200/1000)+(201*1000)+ (6120/1000)+(1234/1003)+(291*1000)+2 

when you could do functions to avoid the brackets...but meh D:

eAi - WHO GOD D:

Posted
Why would you even use a function for something simple like this? I'm going to nominate this topic as the longest for a too simple question of 2011 :|

I don't know.. maybe to prevent doing this:

(6000/1000)+(1200/1000)+(201*1000)+ (6120/1000)+(1234/1003)+(291*1000)+2 

when you could do functions to avoid the brackets...but meh D:

eAi - WHO GOD D:

this would look as ugly as now if u would have to call the func for all of them.

Posted
megaman54 : How to covert milliseconds to seconds?

JR10 : ms / 1000.

megaman54 : What function is that?

JR10 : What?

Just divide the milliseconds.

milliseconds / 1000

megaman54 : Yes, but i need the script to calculate it. I mean, i type a command like this: /calc then it outputs that in seconds. What function should i use for this?

JR10 : Dude, I said divide it.

Milliseconds / 1000 

Oh yeah.

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...