Buy Now

Generic Lists

< Previous | Contents | Manuals Home | Boris FX | Next >

‌Generic Lists

You can create generic indexed lists of objects

Mylist = [1, 2, “buckle my shoe”]

and subsequently change or retrieve the components with Mylist[2], for example. You can tack on additional items to the last slot, with Mylist[4] = 3, Mylist[5]=4, etc. It is an error to perform Mylist[10] = “why?” because that would leave a hole.

You can create a new empty list to add items to

MyNewEmptyList = [ ]

You can also create associative lists with

Color[“apple”] = “red” Color[“pear”] = “green”

You can access Color[2] as well, at this point. #Color is the number of elements, 2 in this example

Color.isKeyed is the number of keys actually set in the array; values

added with no key aren’t counted.

Color.keys is the list [“apple”, “pear”]. Note that there may be fewer keys than elements in the list, if some elements have been added without keys, using numeric subscripts.

Color.key(2) = “pear”, ie the key for the nth item in the list, or a null if element has no key.

Color.index(“pear”) = 2, ie the index of a key in the list, or 0 if it cannot be

found.

Color.contains("peach") = 0, ie false.

Color.remove(“pear”) or Color.remove(2) to remove a list element. Be

aware that Sizzle subscripting creates copies of the list, so you can’t directly remove an element from a list inside another list. See the example at the end of this section.

Sizzle lets you create JSON-style hierarchical lists with optional fixed keys: the keys must be string constants, not an expression in its own right. There’s no need/desire to distinguish between keyed and unkeyed lists here, so an example looks like this:

obj = [

"answer" : 42, "isBoolean" : true, "sequence" : [2, 3, 4], "errors" : null, "nested" : [

"hummingbird" : "ruby", "sticks": 39, "finished" : false

],

"unknown" : "whether this will be helpful"

]


Scene.JSONwrite("C:/tmp/handmade.json", obj)

As you can see, the produced object can be written to a file to produce this output:

{

"answer": 42, "isBoolean": true, "sequence": [

2,

3,

4

],

"errors": null, "nested": {

"hummingbird": "ruby", "sticks": 39, "finished": false

},

"unknown": "whether this will be helpful"

}

There are complementary functions JSONread, JSONencode (to a string, not a file), and JSONdecode (a string to a potentially-complex nested object).

Note the presence of true, false, and null entries in the input and output; they are all preserved. The Booleans true and false are variables containing the corresponding special Boolean value. They behave as numbers in almost all contexts. To determine if a value read in is a number or a Boolean, use typeof(value) to produce either “Boolean” or “Double”.

With the “obj” variable listed above, you cannot do this:

obj["nested"].remove("sticks")

because “sticks” is removed from the copy of obj[“nested”]. Instead, do this:

nested = obj["nested"] nested.remove("sticks") obj["nested"] = nested

This applies to attribute assignment as well, and may be addressed in some future release.

©2026 Boris FX, Inc. — UNOFFICIAL — Converted from original PDF.


Subscribe to our newsletter

Get all the latest news, blog posts and product updates from Boris FX, delivered directly to your inbox.

In order to provide you with the content requested, we need to store and process your personal data. For more information on how to unsubscribe and our commitment to protecting your privacy, please review our Privacy Policy.

Welcome!

Thanks for opting-in to our newsletter. You'll receive an email momentarily with your confirmation.

Please select your language

The website is currently localized into the following languages