Author Topic: Official Coding Resources Thread (02/29/2016)  (Read 51060 times)

Please remove the link to my isNumber function.
I prefer Clockturn's isNumber function.
Code: [Select]
function isNumber(%string)
{
if(%string <= 999999 && (%string >= -999999))
{
// Fast solution
return %string $= %string * 1;
}

else
{
// Slow solution
%dot = 0; // Track if period present
%sci = 0; // Track if scientific notation present

for(%j = 0; %j < strLen(%string); %j++)
{
%c = getSubStr(%string, %j, 1);

if(%c $= "-")
{
if(%sci == -1)
{
%sci = 1; // Negative powers
}

else if(%j != 0)
{
return false; // Negative not the first character
}

continue;
}

if(%c $= ".")
{
if(%dot || %j == 0)
{
return false; // Multiple periods or nothing before the period
}

else
{
%dot = 1;
}

continue;
}

if(%c $= "e")
{
if(%sci != 0)
{
return false; // Multiple Es present
}

else
{
%sci = -1;
}

continue;
}

if(%c $= "+")
{
if(%sci != -1)
{
return false; // + is not part of e+ scientific notation
}

else
{
%sci = 1;
}

continue;
}

if(%sci == -1 || strPos("0123456789", %c) == -1)
{
return false; // An E was present without a + or the current character is not a number
}
}

if(%sci == -1)
{
return false; // Last character was an E.
}

return true; // Gamut has been run, nothing returned, ergo it is fine
}
}

I ran into trouble trying to sort things with SimSets. I guess that Blockland doesn't come with functions like sort() and reorderChild()?
Anyway, I found a sort function and scripted one for reorderChild(), here:  http://pastebin.com/FGjJvSwv
« Last Edit: December 26, 2013, 01:47:11 PM by dUMBELLS »

Anyway, I found a sort function and scripted one for reorderChild(), here:  (soon)

The link was there earlier. What happened?

Is this good?

Object positioning (See or get an object from a position)

Useful for checking objects in a position using a special typemask (if needed to), such as grapple ropes (So they don't hook into space)

« Last Edit: December 26, 2013, 01:47:02 PM by dUMBELLS »



I can't...
Too complicated...
;-;


I can't...
Too complicated...
;-;
If you're referring to TorqueScript, it's really an incredibly simple language compared to say, C++.

I can't...
Too complicated...
;-;

if you persevere you can do anything! 100th reply

Could someone make a getWeekOfMonth() or getWeekOfYear() function for me please?

I've been using this library quite frequently. It's pretty simple, but damn useful.
Mold made it, I added the getRandomItemFromList function.
Code: [Select]
// --- List Support functions. Ask Mold, I don't know.
// - Todo: Comment this. It's a very useful resource.
// Originally by Mold
// Modified by Lugnut

//List functions found in Event_Minigame

function addItemToList(%string, %item)
{
if(hasItemOnList(%string, %item))
return %string;

if(%string $= "")
return %item;
else
return %string SPC %item;
}

function hasItemOnList(%string,  %item)
{
for(%i=0;%i<getWordCount(%string);%i++)
{
if(getWord(%string, %i) $= %item)
return 1;
}
return 0;
}

function removeItemFromList(%string, %item)
{
if(!hasItemOnList(%string, %item))
return %string;

for(%i=0;%i<getWordCount(%string);%i++)
{
if(getWord(%string, %i) $= %item)
{
if(%i $= 0)
return getWords(%string, 1, getWordCount(%string));
else if(%i $= getWordCount(%string)-1)
return getWords(%string, 0, %i-1);
else
return getWords(%string, 0, %i-1) SPC getWords(%string, %i+1, getWordCount(%string));
}
}
}

function getRandomItemFromList(%string)
{
if(%string $= "")
return false;

%num = getRandom(0, getWordCount(%string));

return getWord(%string, %num);
}
Could someone make a getWeekOfMonth() or getWeekOfYear() function for me please?
Day of month modulo 7?
Day of year modulo 7?
It's that simple... I think.

Day of month modulo 7?
Day of year modulo 7?
It's that simple... I think.
Thanks. I works. I found a function to get the day of the month, but not the day of the year. I only needed one or the other though.
Code: [Select]
function getWeekOfMonth()
{
return getWord(getCompileTimeString(), 1) % 7;
}

Ehm, I'm pretty sure getCompileTimeString() returns the time of compilation of the current build, not the current time.