Vice City: Multiplayer

Community Projects => SLC's Squirrel Plugin => Bug Reports => Topic started by: EK.IceFlake on March 3rd, 2017, 05:01 AM

Title: the index 'Timer' does not exist
Post by: EK.IceFlake on March 3rd, 2017, 05:01 AM
I was trying to use the Timer function, however, it returned an index doesn't exist error.
Code: [Select]
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)
Title: Re: the index 'Timer' does not exist
Post by: . on March 3rd, 2017, 05:46 AM
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:
Code: [Select]
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:
Code: [Select]
[USR] 31184
[USR] 8.66223

And the timer is used to time code:
Code: [Select]
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:
Code: [Select]
[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:
Code: [Select]
SqRoutine(this, print, 100, 3, "HELLO WORLD");

Output:
Code: [Select]
[USR] HELLO WORLD
[USR] HELLO WORLD
[USR] HELLO WORLD

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

Output:
Code: [Select]
[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(http://forum.vc-mp.org/?topic=4103.0). In fact, that one is a back-port of this one.