1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
|
Object
======
In SurgeScript, all objects are also instances of `Object`. This means that the properties and functions listed below are available for all objects:
Properties
----------
#### parent
`parent`: object, read-only.
Reference to the parent object.
#### childCount
`childCount`: number, read-only.
The number of children of the object.
#### __name
`__name`: string, read-only.
The name of the object.
#### __active
`__active`: boolean.
Indicates whether the object is active or not.
Objects are active by default. Whenever an object is set to be inactive, its state machine is paused. Additionally, the state machines of all its descendants are also paused.
#### __functions
`__functions`: [Array](/reference/array) object, read-only.
The functions of this object represented as a collection of strings.
#### __timespent
`__timespent`: number, read-only.
The approximate time spent in this object in the last frame (in seconds).
#### __file
`__file`: string, read-only.
The source file of this object.
*Available since:* SurgeScript 0.5.3
Functions
---------
#### spawn
`spawn(objectName)`
Spawns an object named `objectName`.
*Arguments*
* `objectName`: string. The name of the object to be spawned / instantiated.
*Returns*
A new object of the desired name. Note that the newly created object will be a child of `this`.
#### destroy
`destroy()`
Destroys the object.
#### child
`child(childName | childId)`
Looks for a child named `childName` (or matching `childId`).
*Arguments*
* `childName`: string. The name of the desired child.
* `childId`: number. The id of the desired child, an integer between `0` and `childCount - 1`, inclusive.
*Returns*
The desired child, or `null` if there is no such object.
#### children
`children(childName)`
Finds all children named `childName`. Since this function spawns a new array at each call, it's recommended to cache its return value.
*Available since:* SurgeScript 0.5.4
*Arguments*
* `childName`: string. The name of the desired children.
*Returns*
A new array containing all children named `childName`. If no such children are found, an empty array is returned.
#### childWithTag
`childWithTag(tagName)`
Finds a child tagged `tagName`.
*Available since:* SurgeScript 0.5.4
*Arguments*
* `tagName`: string. The name of a tag.
*Returns*
A child tagged `tagName`, or `null` if there is no such object.
#### childrenWithTag
`childrenWithTag(tagName)`
Finds all children tagged `tagName`.
*Available since:* SurgeScript 0.5.4
*Arguments*
* `tagName`: string. The name of a tag.
*Returns*
A new array containing all children tagged `tagName`. If there are no such children, an empty array is returned.
#### sibling
`sibling(siblingName)`
Looks for a sibling named `siblingName`. Two objects are siblings if they share the same parent.
*Arguments*
* `siblingName`: string. The name of the desired sibling.
*Returns*
A sibling of name `siblingName`, or `null` if there is no such object.
#### findObject
`findObject(objectName)`
Finds a descendant (child, grand-child, and so on) named `objectName`. Since this function traverses the [object tree](/tutorials/object_tree), it's recommended to cache its return value. Do not use it in loops or states, as it might be slow.
*Arguments*
* `objectName`: string. The name of the desired object.
*Returns*
A descendant named `objectName`, or `null` if there is no such object.
*Example*
```
object "TestObject"
{
// will search for SomeOtherObject in the Application
obj = Application.findObject("SomeOtherObject");
state "main"
{
if(obj != null)
Console.print("Found the object.");
else
Console.print("Object not found.");
destroy();
}
}
```
#### findObjects
`findObjects(objectName)`
Finds all descendants named `objectName`. Since this function traverses the [object tree](/tutorials/object_tree), it's recommended to cache its return value. Do not use it in loops or states, as it might be slow.
*Available since:* SurgeScript 0.5.4
*Arguments*
* `objectName`: string. The name of the objects to be found.
*Returns*
A new array containing all descendants named `objectName`. If no such descendants are found, an empty array is returned.
#### findObjectWithTag
`findObjectWithTag(tagName)`
Finds a descendant tagged `tagName`. Since this function traverses the [object tree](/tutorials/object_tree), it's recommended to cache its return value. Do not use it in loops or states, as it might be slow.
*Available since:* SurgeScript 0.5.4
*Arguments*
* `tagName`: string. The name of a tag.
*Returns*
A descendant tagged `tagName`, or `null` if there is no such object.
#### findObjectsWithTag
`findObjectsWithTag(tagName)`
Finds all descendants tagged `tagName`. Since this function traverses the [object tree](/tutorials/object_tree), it's recommended to cache its return value. Do not use it in loops or states, as it might be slow.
*Available since:* SurgeScript 0.5.4
*Arguments*
* `tagName`: string. The name of a tag.
*Returns*
A new array containing all descendants tagged `tagName`. If no such descendants are found, an empty array is returned.
#### toString
`toString()`
Converts the object to a string. This function is designed to be overloaded by your own objects.
*Returns*
A string.
#### equals
`equals(otherObject)`
Compares `this` object to `otherObject`. This function is designed to be overloaded by your own objects.
*Arguments*
* `otherObject`: object. An object to compare `this` to.
*Returns*
Returns `true` if the objects are equal; `false` otherwise.
#### hasFunction
`hasFunction(functionName)`
Checks if the object has a function named `functionName`.
*Arguments*
* `functionName`: string. The name of the function.
*Returns*
Returns `true` if the object has a function named `functionName`.
#### hasTag
`hasTag(tagName)`
Checks if the object has been tagged with `tagName`.
*Arguments*
* `tagName`: string. The name of the tag.
*Returns*
Returns `true` if the object has been tagged with `tagName`.
#### __invoke
`__invoke(functionName, paramsArray)`
Invokes function `functionName`, passing the parameters specified in `paramsArray`. Please note that the number of elements of `paramsArray` must be the same as the number of parameters required by the function to be invoked.
*Available since:* SurgeScript 0.5.2
*Arguments*
* `functionName`: string. The name of the function to be called.
* `paramsArray`: [Array](/reference/array). The parameters to be passed to the function.
*Returns*
Returns the value returned by the invoked function.
*Example*
```
// The program below will print:
// 12
// 12
// true
object "Application"
{
state "main"
{
Console.print(this.sum(5, 7));
Console.print(this.__invoke("sum", [5, 7]));
Console.print(sum(5, 7) == __invoke("sum", [5, 7]));
Application.exit();
}
fun sum(a, b)
{
return a + b;
}
}
```
#### __arity
`__arity(functionName)`
Returns the number of arguments of function `functionName`, if it's defined. If it's not defined, zero will be returned.
*Available since:* SurgeScript 0.5.4
*Arguments*
* `functionName`: string. The name of a function.
*Returns*
The number of arguments of the specified function, or zero if the function is not defined.
|