Liberty Unleashed
Scripting => Script Snippets => Topic started by: Shadow. on March 09, 2013, 11:55:02 am
-
Return full time in array
function GetTimeTable()
{
timestamptable <- array(5,0);
local time = GetFullTime().tostring();
timestamptable[0] = time.slice(0,3);
timestamptable[1] = time.slice(4,7);
timestamptable[2] = time.slice(8,10);
timestamptable[3] = time.slice(11,19);
timestamptable[4] = time.slice(20,24);
return timestamptable;
}
How to use it: GetTimeTable()[id], id can be 0,1,2,3,4 but not higher or lower. 0 returns day in 3 letters, 1 returns month in 3 letters, 2 returns day number in 1 integer, 3 returns the time in 8 characters, 4 returns year in 1 integer.
Example:
function onConsoleInput(cmd,text)
{
print("Executing command: " + cmd + " with params: " + text + " at " + GetTimeTable()[0] + "/" + GetTimeTable()[1] + "/" + GetTimeTable()[3] );
}
Sending script error messages w/o forcing an error 2 ways.
function PrintErrorMessage(errortitle,optionalparams)
{
if(optionalparams)
throw("\"" + errortitle + "\" , possible cause: " + optionalparams);
else
throw("\"" + errortitle + "\"");
}
How to use it: PrintErrorMessage("hello","apple");
Images:
(http://s17.postimage.org/r95b9m79b/bwah.jpg)
Method 2
function PrintErrorMessage2(errortitle,optionalparams)
{
if(optionalparams)
error("Error at \"" + errortitle + "\" , possible cause: " + optionalparams);
else
error("Error at \"" + errortitle + "\"");
}
How to use it: PrintErrorMessage("hello","apple");
Images: (http://s22.postimage.org/s5uypc87l/bwah.jpg)
To be continued.
If you have useful snippets, post them over here.
PS: SQ3.0.2 is the Squirrel version used by LU.
-
Return full time in array
function GetTimeTable()
{
timestamptable <- array(5,0);
local time = GetFullTime().tostring();
timestamptable[0] = time.slice(0,3);
timestamptable[1] = time.slice(4,7);
timestamptable[2] = time.slice(8,10);
timestamptable[3] = time.slice(11,19);
timestamptable[4] = time.slice(20,24);
return timestamptable;
}
How to use it: GetTimeTable()[id], id can be 0,1,2,3,4 but not higher or lower. 0 returns day in 3 letters, 1 returns month in 3 letters, 2 returns day number in 1 integer, 3 returns the time in 8 characters, 4 returns year in 1 integer.
I use GetFullTime() always, but not in that way, I use this
local t = GetFullTime(), clock = GetTok( t, " ", 4 ), hour = GetTok( clock, ":", 1 ), minute = GetTok( clock, ":", 2 );
what is your opinion about my method?
-
well yeah, either way is good, I was bored back then and I wrote those snippets ;d
-
There is a default squirrel function called date() which will return a table with all data you need.
No need to parse a string..
local time = date(GetTime());
timestamptable <- array(5,0);
timestamptable[0] = time.day;
timestamptable[1] = time.month;
timestamptable[2] = time.day;
timestamptable[3] = format("%02d:%02d:%02d", time.hour, time.min, time.sec);
timestamptable[4] = time.year;
Credits to Gudio (http://vcmp.liberty-unleashed.co.uk/forum/index.php?topic=1017.msg6164#msg6164) for the code snippet