Jump to content

Recommended Posts

Posted (edited)

I'm trying to show how much time has elapsed in a mission. Here is what I have:

 

function SecondsToClock(seconds)

local seconds = tonumber(seconds)

 

if seconds <= 0 then

return "00:00:00";

else

hours = string.format("%02.f", math.floor(seconds/3600));

mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)));

secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60));

return hours..":"..mins..":"..secs

end

end

 

local _theTime = mist.getClockString(SecondsToClock(timer.getTime()))

local _string = 'Current Mission Time: ' .. _theTime

trigger.action.outTextForGroup(1, _string, 30, false)

 

 

The output is always 00:00:00

 

The timer.getTime() function is supposed to give the seconds elapsed so I take that value, convert it to HH:MM:SS converted to string to display. I'm not sure if I'm over complicating things. There should be a way to do this. Googling doesn't reveal much.

Any help would be appreciated.

 

Thanks

Edited by wraith70
Posted

mist.getClockString() is looking for a number value as in input. It is getting a string of numbers with ':' between each. It sets a default value of 0 and then changes that value if it is a number or a special table, thus its showing as 00.

 

You should be able to just call mist.getClockString(timer.getTime()) to get what you are wanting.

 

TBH using (timer.getAbsTime() - timer.getTime0()) might be better since those values deal specifically with mission time that you see in the assorted clocks in game.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Posted
mist.getClockString() is looking for a number value as in input. It is getting a string of numbers with ':' between each. It sets a default value of 0 and then changes that value if it is a number or a special table, thus its showing as 00.

 

You should be able to just call mist.getClockString(timer.getTime()) to get what you are wanting.

 

TBH using (timer.getAbsTime() - timer.getTime0()) might be better since those values deal specifically with mission time that you see in the assorted clocks in game.

 

Thanks Grimes.

I've tried both and works very well.

 

--ELAPSED TIME 1

local _theTime = mist.getClockString(timer.getTime())

local _string = 'Current Mission Time: ' .. _theTime

trigger.action.outTextForGroup(1, _string, 30, false)

 

-- ELAPSED TIME 2

local _theTime = mist.getClockString(timer.getAbsTime() - timer.getTime0())

local _string = 'Current Mission Time: ' .. _theTime

trigger.action.outTextForGroup(1, _string, 30, false)

  • Recently Browsing   0 members

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