TorqueScript Commands
From TDN
Clipboard
Miscellaneous functions to control the clipboard and clear the console.
cls
cls();
Clears all the output in the console window. It does not effect the console log.
getClipboard
%text = getClipboard();
Returns the text that is currently in the clipboard buffer or an empty string.
setClipboard
%succeeded = setClipboard( "my text" );
Set some text into the system clipboard. It returns true if successful else returns false.
ConsoleDoc
Console self-documation functions. These output pseudo C++ suitable for feeding though Doxygen or another auto documentaion tool.
dumpConsoleClasses
Dumps all declared console classes to the console.
dumpConsoleFunctions
Dumps all declared console functions to the console.
StringFunctions
strcmp
%relation = strcmp(%AString, %BString);
Do a case-sensitive string comparison and return the relation of the first string to the second.
If %AString < %BString then %relation < 0.
If %AString > %BString then %relation > 0.
If %AString $= %BString then %relation == 0.
stricmp
%relation = stricmp(%AString, %BString);
Do a case-insensitive string comparison and return the relation of the first string to the second.
If strlwr(%AString) < strlwr(%BString) then %relation < 0.
If strlwr(%AString) > strlwr(%BString) then %relation > 0.
If strlwr(%AString) $= strlwr(%BString) then %relation == 0.
strlen
%length = strlen(%AString);
Get the number of characters in a string.
strstr
%pos = strstr(%string, %substr);
Locate the first occurrence of %substr within %string, returning the character index of the first match. (A result of -1 indicates no match.)
strpos
%pos = strpos(%string, %substr [, %index])
Find the first occurrence of %substr within %string starting from the given %index value. If no %index is given then 0 is assumed. Returns -1 if no occurrence of string is found within substr.
Example:
%haystack = "things that go bringg!"; %needle = "ing"; %pos = 0; while (true) { %pos = strpos(%haystack, %needle , %pos); if (%pos < 0) break; echo("Matched at " @ %pos); %pos++; }
ltrim
%trimmed = ltrim(%string)
Left trim. Make a copy of %string with the white space trimmed off of the front end (i.e., the left end).
rtrim
%trimmed = rtrim(%string)
Right trim. Make a copy of %string with all white space trimmed off of the end (i.e., the right end).
trim
%trimmed = trim(%string)
Make a copy of %string with the white space removed from both ends. Equivalent to ltrim(rtrim(%string)).
stripChars
%stripped = stripChars(%string, %chars)
Make a copy of %string with all the characters contained in the string %chars stripped out.
strlwr
%lowercaseString = strlwr(%AString);
Make a copy of %AString with all alphabetical characters converted to lowercase. Typically used when comparing user input to a pre-determined string.
strupr
%uppercaseString = strupr(%AString);
Make a copy of %AString with all alphabetical characters converted to uppercase.
strchr
Find the first occurrence of a character within %string.
%pos = strchr(%string, "?");
strreplace
Decalred in ConsoleFunctions.cc as
ConsoleFunction(strreplace, const char *, 4, 4, "(string source, string from, string to)
%mynewstring = strreplace(%mystring,%oldval,%newval);
Replaces %oldval with %newval in %mystring
getSubStr
Returns the substring of str, starting at start, and continuing getSubStr(string str, int start, int numChars)
%WeaponImage = "AK47Image"; %pos = strStr(%weaponImage,"Image"); %Weapon = getSubStr(%WeaponImage,0,%pos); echo("Pos = " @ %pos @ " Weapon = " @ %Weapon); ----- Pos = 4 Weapon = AK47
FieldManipulators
getWord
%word = getWord(%field, n);
Extracts the nth (0-based index) word from a field. For example, if %field is "21.0 512 64.3", getWord(%field, 1); will return 512.
getWords
%word = getWords(%string, %startPos, %endPos);
Extracts all space-delimited words from a string, starting at the %startPos position in the string and ending at the %endPos position. Note that the first word of a string is position 0.
For example, if %string is "Who's your daddy?", getWords(%string, 0, 1); will return Who's your.
setWord
%newField = setWord(%field, n, newValue);
Sets the nth (0-based index) word in a field to newValue. For example, if %field is "21.0 512 64.3", %newField = setWord(%field, 1, 3.14); will return "21.0 3.14 64.3". Note that the original %field remains unchanged. You must use the returned value (another field) for the changes to be reflected. If you want to change the original field, something like %field = setWord(%field, 1, 3.14); will work splendidly.
removeWord
%string = removeWord(%string, %index);
Returns a modified string after removing the word found at %index
in %string
. Also removes any associated trailing whitespace after the removed word.
getWordCount
%count = getWordCount(%string);
Counts the number of space-delimited words in %string. For example, if %string is "Who's your daddy?", getWordCount(%string); will return 3.
getField
%newfield = getField(%string, %fieldnumber);
the getfield value returns a field in a string. Fields are seperated by ^'s or TAB's so getField("1"TAB"2"TAB"3"TAB",0); would return 1.
getFields
%newstring = getFields( %string, %startfield [ , %endfield ] );
Returns the fields in %string
between %startfield
and %endfield
(or the end of the string if %endfield
is not specified).
setField
%newstring = setField( %string, %index , %replace );
Replaces the field in %string
at %index
with the string %replace
.
removeField
%newstring = removeField(%string, %fieldnumber);
Removes the field in %string
specified by %fieldnumber
. Also removes the associated field termination character following the field located at %filednumber
.
getFieldCount
%count = getFieldCount(%string);
Returns the number of fields in %string
.
getRecord
%newstring = getRecord(%string, %index);
Returns the record located at %index
(0 based) contained in %string
. Each record within a string is terminated by a newline character, i.e. the "NL" operator.
getRecords
%newstring = getRecords(%string, %firstrecord [, %lastrecord ] );
Returns a range of records contained in %string
beginning at %firstrecord
to %endrecord
(or the end of %string
if %endrecord
is not specified).
setRecord
%newstring = setRecord(%string, %index, %replacement);
Replaces the record in %string
at %index
with %replacement
.
removeRecord
%newstring = removeRecord(%string, %index);
Removes the record from %string
located at %index
. Also removes the associated record delimiter.
getRecordCount
%count = getRecordCount(%string);
Returns the number of records contained in %string
.
firstWord
%word = firstWord(%string);
Extracts the first space-delimited word from a string. For example, if %string is "21.0 512 64.3", firstWord(%string); will return 21.0.
See also: restWords()
restWords
%word = restWords(%string);
Extracts all space-delimited words from a string beginning from position 1 (the second word of the string) to the end of the string. For example, if %string is "Who's your daddy?", restWords(%string); will return your daddy?.
See also: firstWord()
NextToken
TaggedStrings
detag
getTag
getTag(%string);
Use the getTag function to retrieve the tag ID associated with a previously tagged string. Returns the tag ID of the string. If the string was not previously tagged, it gets tagged and the new tag ID is returned.
addTaggedString
removeTaggedString
getTaggedString
buildTaggedString
Output
echo
Outputs text to the console.
echo("This is shown in the console.");
See also: warn(), error()
warn
Outputs coloured text to the console.
warn("This is shown in the console.");
See also: echo(), error()
error
Outputs brightly coloured text to the console.
error("This is shown in the console.");
See also: echo(), warn()
expandEscape
collapseEscape
setLogMode ( mode )
Sets the log mode and enables logging. Logging allows us to track what is happening within the code.When we use the Echo(), Warn(), or Error() functions, their output is sent to the console.log file, in the root game folder. mode is the logging mode.
remarks: This function is often used at the beginning of main.cs package.
Example:
SetLogMode(2); // overwrites existing log file & closes log file at exit.
setEchoFileLoads
MetaScripting
call
Calls a function with the given argument(s).
call(funcName, [,args ...])
compile
compile("./main1.cs"); // edit this line in any .cs file located in root game folder // this command compiles the file main1.cs and results with the .dso file
exec
Loads a script into memory for use in the application.
exec ("pathto/script");
eval
eval(%string);
Immediately executes an arbitrary string as a command statement. The engine first completely evaluates the value of the string, and then executes it as if it was the next statement in the script. The %string can be a variable, a string (in quotations), or a calculated string (such as with concatenation using @, SPC, or TAB). For instance, the script statement eval("$var1 =" SPC "$var2;"); would generate the string "$var1 = $var2;" and then execute it, which would then set the value of $var1 equal to the value of $var2. There are however alot of caveats when using eval you should be aware of. For more information, you may wish to see this thread... http://www.garagegames.com/mg/forums/result.thread.php?qt=28808
(NOTE: The above URL links to a T2D page while this Wiki entry is not T2D specific. The information contained within the link should be entered here, not hyperlinked. /Stefan Lundmark)
export
Bold textItalic text
deleteVariables
trace
If trace is turned on, Torque prints messages to the console each time the engine enters or leaves a console function, along with the return value (if any).
trace(true); // Turns on tracing. trace(false); // Turns off tracing.
debug
FileSystem
findFirstFile
findNextFile
getFileCount
getFileCRC
Calculate the Cyclic-Redundancy-Check for a file. Returns the CRC-32 value for the file.
isFile
isWriteableFileName
fileExt
fileBase
fileName
filePath
Packages
isPackage
isActivePackage
activatePackage
deactivatePackage
SimFunctions
NPatch
OpenGLTex
GameFunctions
CameraFunctions
getPosition() ---- '''Purpose''' Use the getPosition method to find the current world position of the camera. '''Returns''' Return a vector containing the XYZ position of the camera. 45
Containers
Platform
ShowTool
Net
ServerQuery
Interiors
VectorMath
VectorAdd
VectorSub
VectorScale
VectorNormalize
VectorDot
VectorCross
VectorDist
VectorLen
VectorOrthoBasis
MatrixMath
RandomNumbers
GeneralMath
Please note all of this information is borrowed from http://www.egotron.com/torque/old_script.html And may or may not be current, however what functions I have personally tried do appear to work properly.
mSolveQuadratic(a,b,c) Used to solve for Quadratic Returns a string %quad = mSolveQuadratic(a,b,c);
mSolveCubic(a,b,c,d) Used to solve for a Cube Returns a string %cube = mSolveCubic(a,b,c,d);
mSolveQuartic(a,b,c,d,e) Used to solve for a Quartic Returns a string %quartic = mSolveQuartic(a,b,c,d,e);
mFloor(float) Used to return the largest integral value not greater than "float" Returns a numeric %pageLines = mFloor(%chatScrollHeight / %textHeight); if (%pageLines <= 0) %pageLines = 1;
mCeil(float) Used to return the smallest integral value not less than "float" Returns a numeric %min = mCeil(%chatScrollHeight / %textHeight);
mFloatLength(float, numDecimals) Used to return float with a "numDecimals" padding Returns a numeric %newFloat = mFloatLength((7/3),5);
mAbs(float) Used to return absolute value of float returns a string %abs = mAbs(76.3);
mSqrt(float) Used to return the square root (sqrt) of float Returns a numeric %sqrt = mSqrt(69);
mPow(floatA,floatB) Used to get the value of floatA raised to the power of floatB Returns a numeric %pow = mPow(2,4);
mLog(float) Used to return the natural logarithm of Returns a numeric %log = mLog(7654.98);
mSin(float) Used to return the "sine" of float measured in radians Returns a numeric %sin = mSin(65);
mCos(float) Used to return the "cosine" of float measured in radians Returns a numeric %cos = mCos(69);
mTan(float) Used to return the "tangent" of float Returns a numeric %tan = mTan(87.6);
mAsin(float) Used to return the "arc sine" of float returns a numeric %asin = mAsin(-3,8);
mAcos(float) Used to return the "arc cosine" of float Returns a numeric %acos = mAcos(-8,3);
mAtan(float) Used to return the "arc tangent" of float Returns a numeric %atan = mAtan(-10,3);
mRadToDeg(float) Used to convert radiant to degrees Returns a numeric %r2d = mRadToDeg(5);
mDegToRad(float) used to convert degrees to radians Returns a numeric %c2r = mDegToRad(171);
Memory
Redbook
Video
NetInterface
NetStringTable
Containers
- Note: These only work server-side.