1.0 - JS/C++ Arrays in Torque - basically beta testing this stuff
Description
this is a script i've been working on that makes it easier to create and maintain arrays in torquescript. you can now find a matching item, filter items, get the length, make static and dynamic arrays...
Download
Documentation
- simObjectID Array(%length,%dynamic,%i0...%i13)
- Array Object "constructor". Creates an array you can later edit and manipulate
with the assigned class functions. %length is the length of the new array, %dynamic is a bool and determines wether the resulting array can use ::pushNew() and ::popLast(), %i0 through %i13 are optional values to create in the new array in their respective indexes. The return value is the constructed array.
- bool isArray(%array)
- %array is a SimObject ID. The function determines if the Object ID you've
entered is of an Array Instance, which will return true if it is, and false otherwise. You might not need this, but it is used by all following functions.
- bool ArrayInstance::isDynamicArray()
- The function determines if the array you're testing for is a Dynamic Array,
which will return true if it is, and false otherwise. A dynamic array is an array that can get its length changed using ::pushNew()/::popLast()
- int ArrayInstance::getLength()
- Gets the length of the array instance you're testing for.
Returns the length on success, -1 otherwise.
- bool ArrayInstance::setIndex(%index, %value)
- Sets input index %index to %value. Returns true on success, false otherwise.
- bool ArrayInstance::pushNew(%value)
- Creates a new entry with %value in array, consequently increasing the array length.
Returns the new length on success, -1 otherwise.
- int ArrayInstance::popLast()
- Removes the latter entry in array, consequently decreasing the array length.
Returns the new length on success, -1 otherwise.
- any ArrayInstance::getIndex(%index)
- Gets the value at index %index.
Returns the value on success, "" otherwise.
- bool ArrayInstance::forEach(%mode,%name,%i0...%i13)
- Performs an action determined by %mode.
There are two possible forEach modes: "method" : Calls a class function on all array items using arguments %i0 through %i13. "field" : Changes all object/tagged fields named %name on all array items to %i0. Returns true on success, false otherwise.
- string ArrayInstance::toString(%emptyfilter)
- Outputs a list of all values ordered by index and separated by spaces.
Empty indexes can be left blank or replaced with %emptyfilter. Returns the list on success, "" otherwise.
- bool ArrayInstance::remove(%index)
- Removes the value at index %index, this does not shorten the length of the array.
Returns true on success, false otherwise.
- int ArrayInstance::find(%value)
- Finds the first index to match the value of %value.
Returns the index on success, -1 otherwise.
- arrayID ArrayInstance::filter(%value)
- Creates a new array with all values matching %value.
Returns the new array on success, -1 otherwise.
Feel free to report bugs and things that need fixing.
|