the index 'Timer' does not exist

Started by EK.IceFlake, Mar 03, 2017, 05:01 AM

Previous topic - Next topic

EK.IceFlake

I was trying to use the Timer function, however, it returned an index doesn't exist error.
local timer = SqTime.Timer();I tried dumping SqTime, and this is what I got:
[USR] _typename: (function : 0x000001C4C98AE720)
[USR] __overload_Set2: (function : 0x000001C4C9882CE0)
[USR] GlobalDelimiter: :
[USR] __overload_Set4: (function : 0x000001C4C9883DC0)
[USR] AddSeconds: (function : 0x000001C4C9882A60)
[USR] AndSeconds: (function : 0x000001C4C98835A0)
[USR] AddMillis: (function : 0x000001C4C9883000)
[USR] __overload_constructor1: (function : 0x000001C4C985A490)
[USR] __overload_constructor0: (function : 0x000001C4C985C380)
[USR] __getTable: (table : 0x000001C4C988CFF0)
[USR] __overload_Set3: (function : 0x000001C4C9882EC0)
[USR] AndMinutes: (function : 0x000001C4C9883B40)
[USR] __overload_Set1: (function : 0x000001C4C9882C40)
[USR] cmp: (function : 0x000001C4C9883460)
[USR] AndMilliseconds: (function : 0x000001C4C9883D20)
[USR] AndMillis: (function : 0x000001C4C9882E20)
[USR] AndHours: (function : 0x000001C4C98829C0)
[USR] __setTable: (table : 0x000001C4C988BC10)
[USR] __overload_constructor3: (function : 0x000001C4C985A7F0)
[USR] AddMilliseconds: (function : 0x000001C4C9882B00)
[USR] constructor: (function : 0x000001C4C98824C0)
[USR] AddHours: (function : 0x000001C4C9882920)
[USR] weakref: (function : 0x000001C4C985A520)
[USR] __overload_constructor4: (function : 0x000001C4C98AE690)
[USR] Set: (function : 0x000001C4C9882060)
[USR] AddMinutes: (function : 0x000001C4C9882D80)
[USR] __overload_constructor2: (function : 0x000001C4C985A760)

.

#1
SqTime is used to represent time units in a more standardized way. There's also SqDate, SqDatetime, SqTimestamp and SqTimer. And the last one does not mean what you expect it to mean. They're meant to work with time units and even perform some validation on them

For example:
local tm = SqTime(7, 45, 19); // 7 hours, 46 minutes, 19 seconds
// add another 126 minutes to the above time
tm.AddMinutes(126);
// Get the whole thing as a time-stamp
local ts = tm.Timestamp;
// Print how many seconds there were in total
print(ts.SecondsI);
// => I stands for Integer (F would stand for Float when fractional parts are needed)
// Print how many hours were in total (with fractional part)
print(ts.HoursF);

Outputs:
[USR] 31184
[USR] 8.66223

And the timer is used to time code:
local tm = SqTimer();

for (local n = 0, x = 0; n < 10000000; ++n)
{
    x = (n % x) + x - n; //dummy code to do something
}

// Returns a SqTimestamp with elapsed microseconds
print("Elapsed time: " + tm.Elapsed.Milliseconds);

for (local n = 0, x = 0; n < 10000000; ++n)
{
    x = (n % x) + x - n; //dummy code to do something
}

// Restarts the timer and returns SqTimestamp with elapsed microseconds
print("Elapsed time: " + tm.Restart().Milliseconds);

for (local n = 0, x = 0; n < 10000000; ++n)
{
    x = (n % x) + x - n; //dummy code to do something
}

// Returns a SqTimestamp with elapsed microseconds
print("Elapsed time: " + tm.Elapsed.Milliseconds);

Outputs:
[USR] Elapsed time: 444
[USR] Elapsed time: 899
[USR] Elapsed time: 434

Anyway, those are all still a work in progress.

What you're looking for is probably SqRoutine:
SqRoutine(this, print, 100, 3, "HELLO WORLD");

Output:
[USR] HELLO WORLD
[USR] HELLO WORLD
[USR] HELLO WORLD

Ex:
SqRoutine(this, function(who, what) {
    print(who + " said " + what)
}, 100, 3, "That guy", "hello");

Output:
[USR] That guy said hello
[USR] That guy said hello
[USR] That guy said hello

The SqRoutine works a lot like the one described here. In fact, that one is a back-port of this one.
.