TorqueScript Console Functions 3
From TDN
Section Index
1. OpenAL || 2. Debugging || 3. String Manipulation || 4. Networking || 5. Console || 6. Device I/O || 7. File I/O
8. Packages || 9. Objects || 10. Event Scheduling || 11. Datablocks || 12. Video / Texturing || 13. Special || 14. Resource Management
15. Scene || 16. Containers and Raycasts || 17. Editors || 18. Build || 19. Time || 20. GUIs || 21. Math
|
This quick reference guide was taken directly out of The Game Programmer's Guide to Torque by Edward Maurina. It's an outstanding resource - a must for anyone wanting to get serious about programming in Torque. |
String Manipulation
|
Torque includes a bad word filtering feature that can be used process strings and to replace any words matching words on the list of known bad works. This list is built manually. Bad words are replaced with a user-defined set of random characters. Please note, a small but common list of bad words is already included in the engine. Please refer to the engine source code for this list as a would-be tasteless the list of words here. |
|
[edit] addBadWord( aBadWord ) |
|
Purpose |
|
[edit] containsBadWords( string ) |
|
Purpose |
|
[edit] string filterString( baseString [ , replacementChars ] ) |
|
Purpose
function badWordTest()
{
addBadWord( "poop" );
%testPhrase = "This is the poop!";
%filteredPhrase = filterString( %testPhrase , "@#$*" );
echo("Contains bad words? ==> " , containsBadWords( %testPhrase ) );
echo("Before filtering: ", %testPhrase );
echo("After filtering: ", %filteredPhrase );
}
badWordTest();
Contains bad words? ==> 1
Before filtering: This is the poop!
After filtering: This is the $@@*!
|
|
[edit] strcmp( string1 , string2 ) |
|
Purpose |
|
[edit] stricmp( string1 , string2 ) |
|
Purpose
function strcmptest()
{
echo("Lexicographic comparisons are not the same as arithmetic comparisons...");
echo("100 - 10 == 90, but strcmp( \"100\" , \"10\" ) == " ,
strcmp( "100" , "10" ) );
echo("\n", "Don't forget about case-senstivity...");
echo("strcmp( \"ABC\" , \"abc\" ) == " ,
strcmp( "ABC" , "abc" ) , "\n\n, but \n" );
echo("stricmp( \"ABC\" , \"abc\" ) == " ,
stricmp( "ABC" , "abc" ) );
}
strcmptest();
Lexicographic comparisons are not the same as arithmetic comparisons...
100 - 10 == 90, but strcmp( "100" , "10" ) == 1
Don't forget about case-senstivity...
strcmp( "ABC" , "abc" ) == -1
, but
stricmp( "ABC" , "abc" ) == 0
|
|
[edit] strlwr( sourceString ) |
|
Purpose echo( strlwr( "ABCD123" ) ); // Prints abcd123 |
|
[edit] strupr( sourceString ) |
|
Purpose echo( strupr( "abcd123" ) ); // Prints ABCD123 |
|
A field is a sub-string withing a larger string, where each field is delimted by a NEWLINE character or a TAB character. A newline can be represented as either "\n" or the keyword NL, and a tab can be represented by hitting the TAB key, or by the keyword TAB. |
|
[edit] getField( sourceString , index ) |
|
Purpose // Prints Torque echo( getField( "GPGTGE + " NL "AND" TAB "Torque" TAB "Rocks" , 2 ) ); |
|
[edit] getFieldCount( sourceString ) |
|
Purpose %fields = "You" TAB "must" TAB "buy" TAB "GPGTGE"; echo( getFieldCount( %fields ) ); // Prints 4 |
|
[edit] getFields( sourceString , index [ , endindex ] ) |
|
Purpose // Prints Torque^Rocks (^ is printed TAB in console) echo( getFields( "GPGTGE + " NL "AND" TAB "Torque" TAB "Rocks" , 2 , 3 ) ); // Also prints Torque^Rocks echo( getFields( "GPGTGE + " NL "AND" TAB "Torque" TAB "Rocks" , 2 ) ); |
|
[edit] removeField( sourceString , index ) |
|
Purpose %fields = "Torque" TAB "So" TAB "Totally" TAB "Rocks!"; // %fields will contain three fields: "Torque", "Totally", and "Rocks!". %fields = removeField( %fields, 1 ); |
|
[edit] setField( sourceString , index , replace ) |
|
Purpose // %fields will contain two fields, "Torque" and "Rocks!", %fields = setField( "Torque" TAB "Rock" , 1 , "Rocks!" ); |
|
[edit] strlen( string ) |
|
Purpose // Prints 10 echo( strlen( "0123456789" ) ); |
|
A record is a sub-string withing a larger string, where each record is delimted by a NEWLINE character. A newline can be represented as either "\n" or the keyword NL. |
|
[edit] getRecord( sourceString , index ) |
|
Purpose // Prints Torque echo( getRecord( "GPGTGE + " NL "AND" NL "Torque" NL "Rocks" , 2 ) ); |
|
[edit] getRecordCount( sourceString ) |
|
Purpose %records = "You" NL "must" NL "buy" NL "GPGTGE"; echo( getRecordCount( %records ) ); // Prints 4 |
|
[edit] getRecords( sourceString , index [ , endindex ] ) |
|
Purpose // Prints // Torque // Rocks echo( getRecords( "GPGTGE + " NL "AND" NL "Torque" NL "Rocks" , 2 , 3 ) ); // Also prints // Torque // Rocks echo( getRecords( "GPGTGE + " NL "AND" NL "Torque" NL "Rocks" , 2 ) ); |
|
[edit] removeRecord( sourceString , index ) |
|
Purpose %records = "Torque" NL "So" NL "Totally" NL "Rocks!"; // %records will contain three records: "Torque", "Totally", and "Rocks!". %records = removeRecord( %records, 1 ); |
|
[edit] setRecord( sourceString , index , replace ) |
|
Purpose // %records will contain two records, "Torque" and "Rocks!", %Records = setRecord( "Torque" NL "Rock" , 1 , "Rocks!" ); |
|
[edit] strreplace( sourceString , from , to ) |
|
Purpose
// Prints Torque rocks!
echo( strreplace("Torque is cool!" , "is cool" , "rocks" ) );
|
|
[edit] getSubStr( sourceString , start , count ) |
|
Purpose // Prints 2345 echo( getSubStr( "0123456789" , 2 , 4 ) ); |
|
[edit] strchr( sourceString , char ) |
|
Purpose // Prints 3456789 echo( strchr( "0123456789" , "3" ) ); |
|
[edit] strpos( sourceString , searchString [ , offset ] ) |
|
Purpose // Prints 2 echo( strpos( "This is a test" , "is" ) ); // Prints 5 echo( strpos( "This is a test" , "is" , 3 ) ); |
|
[edit] strstr( sourceString , searchString ) |
|
Purpose // Prints -1 echo( strstr( "This is a test" , "IS" ) ); // Prints 2 echo( strstr( "This is a test" , "is" ) ); |
|
[edit] stripChars( sourceString , chars ) |
|
Purpose sourceString–The string to be modified.
// Prints WowThisIsCool
echo( stripChars("WowxThisy*IsCoolz!" , "*xyz" ) );
|
|
[edit] stripColorCodes( stringtoStrip ) |
|
Purpose Removes TorqueML color codes from the given string. Syntax stringtoStrip—The input string. Returns Returns a copy of stringtoStrip, from which all instances of TorqueML markup color codes have been removed. |
|
[edit] stripMLControlChars( sourceString ) |
|
Purpose |
|
[edit] stripTrailingSpaces( sourceString ) |
|
Purpose // Prints This is a test. echo( stripTrailingSpaces( "This is a " ) SPC "test." ); |
|
[edit] ltrim( sourceString ) |
|
Purpose // Prints This is a test. echo( ltrim( " " TAB " " SPC "This is a test." ) ); |
|
[edit] rtrim( sourceString ) |
|
Purpose // Prints This is a test. echo( rtrim( "This is a " ) SPC "test." ); |
|
[edit] trim( sourceString ) |
|
Purpose // Prints This is a test. echo( trim( " " TAB " " SPC "This is a " ) SPC "test." ); |
|
[edit] nextToken( tokenList , tokenVar , delimeter ) |
|
Purpose
function testTokens( )
{
%myTokens = "A,E,I,O,U";
while( "" !$= %myTokens )
{
%myTokens = nextToken( %myTokens , "theToken" , "," );
echo( %theToken );
}
}
testTokens();
A
E
I
O
U
|
|
A word is a sub-string withing a larger string, where each word is delimted by a SPACE character. A space can be represented as either " " or the keyword SPC. |
|
[edit] firstWord( sourceString ) |
|
Purpose
// a target in range was found so select it
if (%scanTarg)
{
%targetObject = firstWord(%scanTarg);
%client.setSelectedObj(%targetObject);
}
|
|
[edit] getWord( sourceString ,index ) |
|
Purpose
function TerrainEditor::offsetBrush(%this, %x, %y)
{
%curPos = %this.getBrushPos();
%this.setBrushPos(getWord(%curPos, 0) + %x, getWord(%curPos, 1) + %y);
}
|
|
[edit] getWordCount( sourceString ) |
|
Purpose
if ( %pos != -1 )
{
%wordCount = getWordCount( %action );
%mods = %wordCount > 1 ? getWords( %action, 0, %wordCount - 2 ) @ " " : "";
%object = getWord( %action, %wordCount - 1 );
switch$ ( %object )
{
case "upov": %object = "POV1 up";
case "dpov": %object = "POV1 down";
case "lpov": %object = "POV1 left";
case "rpov": %object = "POV1 right";
case "upov2": %object = "POV2 up";
case "dpov2": %object = "POV2 down";
case "lpov2": %object = "POV2 left";
case "rpov2": %object = "POV2 right";
default: %object = "??";
}
return( %mods @ %object );
}
else
{
error( "Unsupported Joystick input object passed to getDisplayMapName!" );
}
|
|
[edit] getWords( sourceString ,index [,endindex]) |
|
Purpose %pos = getWords(%obj.getTransform(), 0, 2); |
|
[edit] removeWord( sourceString ,index) |
|
Purpose %cam = removeWord(%cam, 0, getWord(%pos, 0)); |
|
[edit] restWords( sourceString ) |
|
Purpose
function Heightfield::showTab(%id)
{
Heightfield::hideTab();
%data = restWords(Heightfield_operation.getRowTextById(%id));
%tab = getField(%data,1);
echo("Tab data: " @ %data @ " tab: " @ %tab);
%tab.setVisible(true);
}
|
|
[edit] setWord( sourceString ,index,replace) |
|
Purpose
function WorldEditor::dropCameraToSelection(%this)
{
if(%this.getSelectionSize() == 0) return;
%pos = %this.getSelectionCentroid();
%cam = LocalClientConnection.camera.getTransform();
// set the pnt
%cam = setWord(%cam, 0, getWord(%pos, 0));
%cam = setWord(%cam, 1, getWord(%pos, 1));
%cam = setWord(%cam, 2, getWord(%pos, 2));
LocalClientConnection.camera.setTransform(%cam);
}
|
Section Index
1. OpenAL || 2. Debugging || 3. String Manipulation || 4. Networking || 5. Console || 6. Device I/O || 7. File I/O
8. Packages || 9. Objects || 10. Event Scheduling || 11. Datablocks || 12. Video / Texturing || 13. Special || 14. Resource Management
15. Scene || 16. Containers and Raycasts || 17. Editors || 18. Build || 19. Time || 20. GUIs || 21. Math



