__BUILTIN__

__BUILTIN__

__BUILTIN__ is the script class implementing built in functions. These static methods may be called without specifying __BUILTIN__ explicitly, as in:

write("Hello", " World");

Methods

void writeln(Object obj1, [Object… objn])
void writeln_d(Object obj1, [Object… objn])
void writeln_fatal(Object obj1, [Object… objn])
void writeln_error(Object obj1, [Object… objn])
void writeln_warning(Object obj1, [Object… objn])
void writeln_debug(Object obj1, [Object… objn])
void writeln_developer(Object obj1, [Object… objn])
void write(Object obj1, [Object… objn])
void write_d(Object obj1, [Object… objn])

Each of these methods print to console output a variable length list of objects in the order given with no separator. writeln() and its variants complete the output with a newline character, while write and write_d do not. writeln_d and write_d do the same thing as their counterparts, with the exception that the prints may be disabled with the script_debug_writes command.

The writeln_fatal, writeln_error, writeln_warning, and writeln_developer versions prefix the data with a tag (e.g. ***** ERROR:) to indicate type. These outputs can be filtered using the console_output command. For filtering purposes, the vanilla writeln version has the “info” type.

For example:

writeln("Time=", TIME_NOW, " seconds, Platform", PLATFORM.Name());

Note

The writeln_debug method is simply an alias for writeln_d. It has been added to follow the naming convention of the others.

Note

The output generated by script methods write and write_d is prepended to future write() and writeln() output instead of being written immediately; however, writing a newline character (\n) will print the line immediately. This behavior is to facilitate clean interaction with the console_output command and GUI applications when using sequential calls to write().

string write_str(Object obj1, [Object… objn])

The write_str method allows users to concatenate data and return it as a string. For example:

string str = write_str("Time=", TIME_NOW, " seconds, Platform", PLATFORM.Name());
bool has_attr(Object aObject, string aAttributeName)

Returns ‘true’ if the object has an attribute with the given attribute name.:

if (has_attr(plat, "SensorX")) {
   WsfSensor sensor = plat->SensorX;
   ...
}
int attr_count(Object aObject)

Returns the number of attributes on the object.

Object get_attr(Object aObject, string aName)

Returns the attribute on the object with the name aName.

string attr_name_at(Object aObject, int aIndex)

Returns the name of the aIndex ‘th attribute. aIndex should be in the range [0, attr_count(aObject)]. This method can be used to enumerate all attributes on an object.

Array<string> list_attr(Object aObject)

Returns a list of attribute names on the object.

bool has_script(Object aObject, string aScriptName)

Returns ‘true’ if the object has a script with the given name.:

if (has_script(plat, "specialScript")) {
   plat->specialScript(123);
}
void __print_callstack()

Outputs information about the script(s) currently executing, including file / line numbers, and variable values. This method is only useful for debugging.

void assert(bool aBoolExp)
void assert(bool aBoolExp, string aMessage)

assert() checks that an expression evaluates to ‘true’. If the expression does not evaluate to ‘true’, a callstack is printed and the application exits immediately. If a second parameter is specified, it will be printed along with the assertion error.

When using the script debugger, the assert acts as a breakpoint and execution may be resumed.

WsfPlatform plat = WsfSimulation.FindPlatform("MyPlatform");
assert(plat, "MyPlatform does not exist!");
plat.TurnToHeading(90);