• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[1.2 TFS] getFormattedWorldTime function

xoiox

New Member
Joined
Aug 20, 2009
Messages
46
Reaction score
2
Hi, I've got a problem with function getFormattedWorldTime.
I want to create a condition "if server worldtime is 14:35 or above then function runs"

I tried with:
Code:
if getFormattedWorldTime() >= 1435 then

and I've got this error:
Code:
attempt to compare string with number

Can you help me?
 
never used that function but idk how you can compare 14:35 with 1435, ofc that are not the same thing
what about getWorldTime() (?)
 
Hi, I've got a problem with function getFormattedWorldTime.
I want to create a condition "if server worldtime is 14:35 or above then function runs"

I tried with:
Code:
if getFormattedWorldTime() >= 1435 then

and I've got this error:
Code:
attempt to compare string with number

Can you help me?
The error is saying that the function is expecting a string rather than a number.

Example of usage is for example in a watch, where it will print the in-game time.

E.g
Code:
"The time is " .. getFormattedWorldTime() .. "."

Haven't used this function before, but try printing its results and see what it returns.

But yes, like @StreamSide is saying, it seems like you're looking for the function "getWorldTime()".
 
getWorldTime() works different, because this function is counting time when OT is online.
what?

Code:
function getFormattedWorldTime()
    local worldTime = getWorldTime()
    local hours = math.floor(worldTime / 60)

    local minutes = worldTime % 60
    if minutes < 10 then
        minutes = '0' .. minutes
    end
    return hours .. ':' .. minutes
end
its just getWorldTime() divided again and again
 
Code:
function onThink()
if getWorldTime() >= 1435 then
        for i = 1, #t do
                local light = getTileItemById(t[i], 1479).uid
                local light1 = getTileItemById(t[i], 1480).uid
                if(light >= 0) then
                        doTransformItem(light, 1480)
                        doTransformItem(light1, 1480)
                        else
                        return true
                end
        end
        return true
end
end

So I've just launched OT and starts always with time "14:27", I'm waiting for this globalevent and got this: Failed to execute event: Turn lamps on.
 
Code:
function onThink()
if getWorldTime() >= 1435 then
        for i = 1, #t do
                local light = getTileItemById(t[i], 1479).uid
                local light1 = getTileItemById(t[i], 1480).uid
                if(light >= 0) then
                        doTransformItem(light, 1480)
                        doTransformItem(light1, 1480)
                        else
                        return true
                end
        end
        return true
end
end

So I've just launched OT and starts always with time "14:27", I'm waiting for this globalevent and got this: Failed to execute event: Turn lamps on.
There's no table "t" included in this script
 
Code:
function onThink()
if getWorldTime() >= 1435 then
        for i = 1, #t do
                local light = getTileItemById(t[i], 1479).uid
                local light1 = getTileItemById(t[i], 1480).uid
                if(light >= 0) then
                        doTransformItem(light, 1480)
                        doTransformItem(light1, 1480)
                        else
                        return true
                end
        end
        return true
end
end

So I've just launched OT and starts always with time "14:27", I'm waiting for this globalevent and got this: Failed to execute event: Turn lamps on.
Code:
function getFormattedWorldTime2()
    local worldTime = getWorldTime()
    local hours = math.floor(worldTime / 60)

    local minutes = worldTime % 60
    if minutes < 10 then
        minutes = '0' .. minutes
    end
    return hours .. '' .. minutes
end
2lazy
 
I've just added this new function to global.lua and changed from getWorldTime() to getFormattedWorldTime2() and got error:
Code:
attempt to compare number with string.
My whole globalevent script:
Code:
local t, msg = {
        {x = 5100, y = 5092, z = 7, stackpos = 2},
        {x = 5129, y = 5091, z = 7, stackpos = 2},
        {x = 5129, y = 5095, z = 7, stackpos = 2},
        {x = 5135, y = 5095, z = 7, stackpos = 2},
        {x = 5143, y = 5089, z = 7, stackpos = 2},
        {x = 5143, y = 5093, z = 7, stackpos = 2},
        {x = 5148, y = 5085, z = 7, stackpos = 2},
        {x = 5145, y = 5081, z = 7, stackpos = 2},
        {x = 5149, y = 5081, z = 7, stackpos = 2},
        {x = 5155, y = 5082, z = 7, stackpos = 2},
        {x = 5155, y = 5085, z = 7, stackpos = 2},
        {x = 5160, y = 5085, z = 7, stackpos = 2},
        {x = 5155, y = 5092, z = 7, stackpos = 2},
        {x = 5160, y = 5092, z = 7, stackpos = 2},
        {x = 5143, y = 5076, z = 7, stackpos = 2},
        {x = 5146, y = 5074, z = 7, stackpos = 2},
        {x = 5138, y = 5075, z = 7, stackpos = 2},
        {x = 5141, y = 5072, z = 7, stackpos = 2},
        {x = 5133, y = 5073, z = 7, stackpos = 2},
        {x = 5134, y = 5070, z = 7, stackpos = 2},
        {x = 5129, y = 5073, z = 7, stackpos = 2},
        {x = 5109, y = 5074, z = 7, stackpos = 2},
        {x = 5103, y = 5074, z = 7, stackpos = 2},
        {x = 5094, y = 5074, z = 7, stackpos = 2},
        {x = 5088, y = 5074, z = 7, stackpos = 2},
        {x = 5084, y = 5070, z = 7, stackpos = 2},
        {x = 5080, y = 5070, z = 7, stackpos = 2},
        {x = 5098, y = 5057, z = 7, stackpos = 2},
        {x = 5089, y = 5051, z = 7, stackpos = 2},
        {x = 5088, y = 5048, z = 7, stackpos = 2},
        {x = 5078, y = 5045, z = 7, stackpos = 2},
        {x = 5072, y = 5070, z = 7, stackpos = 2},
        {x = 5061, y = 5074, z = 6, stackpos = 2},
        {x = 5052, y = 5057, z = 6, stackpos = 2},
        {x = 5052, y = 5050, z = 6, stackpos = 2},
        {x = 5070, y = 5046, z = 6, stackpos = 2},
        {x = 5044, y = 5047, z = 5, stackpos = 2},
        {x = 5036, y = 5048, z = 5, stackpos = 2},
        {x = 5037, y = 5041, z = 5, stackpos = 2},
        {x = 5045, y = 5034, z = 6, stackpos = 2},
        {x = 5059, y = 5032, z = 6, stackpos = 2},
        {x = 5062, y = 5027, z = 6, stackpos = 2},
        {x = 5067, y = 5027, z = 6, stackpos = 2},
        {x = 5081, y = 5021, z = 6, stackpos = 2},
        {x = 5084, y = 5017, z = 6, stackpos = 2},
        {x = 5088, y = 5017, z = 6, stackpos = 2},
        {x = 5086, y = 5027, z = 7, stackpos = 2},
        {x = 5095, y = 5030, z = 7, stackpos = 2},
        {x = 5108, y = 5032, z = 7, stackpos = 2},
        {x = 5113, y = 5043, z = 7, stackpos = 2},
        {x = 5118, y = 5043, z = 7, stackpos = 2},
        {x = 5122, y = 5041, z = 7, stackpos = 2},
        {x = 5100, y = 5042, z = 6, stackpos = 2},
        {x = 5094, y = 5042, z = 6, stackpos = 2},
        {x = 5092, y = 5036, z = 6, stackpos = 2},
        {x = 5125, y = 5035, z = 7, stackpos = 2},
        {x = 5130, y = 5035, z = 7, stackpos = 2},
        {x = 5125, y = 5030, z = 7, stackpos = 2},
        {x = 5125, y = 5024, z = 7, stackpos = 2},
        {x = 5125, y = 5017, z = 7, stackpos = 2},
        {x = 5133, y = 5016, z = 7, stackpos = 2},
        {x = 5138, y = 5016, z = 7, stackpos = 2},
        {x = 5138, y = 5020, z = 7, stackpos = 2},
        {x = 5117, y = 5051, z = 7, stackpos = 2},
        {x = 5113, y = 5055, z = 7, stackpos = 2},
},

function onThink()
if getFormattedWorldTime2() >= 1435 then
        for i = 1, #t do
                local light = getTileItemById(t[i], 1479).uid
                local light1 = getTileItemById(t[i], 1480).uid
                if(light >= 0) then
                        doTransformItem(light, 1480)
                        doTransformItem(light1, 1480)
                        else
                        return true
                end
        end
        return true
end
end
 
Back
Top Bottom