This script keeps giving me a error, it works, but I want to get rid of the yellow errors when joining.
The error is:
gamemode\cl_init.lua:502] attempt to perform arithmetic on local 's' (a string value)(Hook: HUDPaint)
The script is:
[lua]
local s = LocalPlayer():GetNetworkedString("cider_TimePlayed"); --How many total seconds do we have
local totalm = math.floor( s / 60 ); --How many total minutes do we have
local h = math.floor( totalm / 60 ); --How many total hours do we have
local m = totalm - h * 60; --Minutes left
s = s - totalm * 60; --Seconds left
table.insert( text, {"Time Played: "..h..":"..m..":"..s.."", "gui/silkicons/table_edit"} );
[/lua]
You need to tostring s.
[lua]local s = tostring(LocalPlayer():GetNetworkedString("cider_TimePlayed"));[/lua]
tonumber
I tried both suggestions but it keeps giving the error.
Don't know if %H or %I are bugged in gmod, but you could always do this:
[code]
local dt = tonumer( LocalPlayer( ):GetNWString( "cider_TimePlayed" ) ) or 0
table.insert( text, { os.date( "Time played: %H:%M:%S", -3600 + dt ), "gui/silkicons/table_edit" } )
[/code]
On the demo site, %H and %I start at 1 rather than the cited zero in the documentation, so you have to offset an hour backwards ( hence -3600 ).
Don't know if this will work correctly in gmod, but it does in a normal environment.
I tried your script, but it gives this error:
[@lua\includes\extensions\string.lua:33] bad argument #1 to 'find' (string expected, got nil)(Hook: HUDPaint)
Edit: I got rid of the error by placing [lua]or 0[/lua] on line 1
There is already and or 0 on the first line :psyduck:
[QUOTE=Kogitsune;27023654]There is already and or 0 on the first line :psyduck:[/QUOTE]
On your script it is but I meant this:
[lua]local s = tonumber(LocalPlayer():GetNetworkedString("cider_TimePlayed")) or 0;[/lua]
That is what it was before.
Like I said, I haven't had the chance to run this in gmod, but codepad gives a different result than the demo on lua.org.
[code]print( os.date( "%H:%M:%S", 1 ) )
print( os.date( ) )[/code]
Expected behavior should be printing "00:00:01" and then the date and time on the server.
Lua.org's demo prints:
01:00:01
And then their local time
codepad prints 00:00:01
So the offset may or may not be needed depending on how gmod handles %H
Sorry, you need to Log In to post a reply to this thread.