Open lucky62 opened 2 years ago
Some of the support is there. Internal functions (notably textmetrics() and fontmetrics(), ref #3684 ) can create objects with strings as their keys, and most of the operations that you might expect can be done on them. You can also import JSON files to create objects, ref #3891 .
What you can't do is to create them directly from an OpenSCAD program. Ref #3088 .
@jordanbrown0, JSON objects are very useful. Are you (or someone else) planning to allow to create a JSON in OpenSCAD program?... :-)
@JustinSDK, hashmap can help also, but still it is a workaround to simulate missing feature..
I'll do it eventually, if somebody else doesn't get to it first.
BOSL2 has a structs library that implements associative arrays like this. The syntax vector["keyname"] could easily be made to be equivalent to the BOSL2 struct equivalent, with one exception. In BOSL2 struct_val(), there is a default argument that is useful. It defaults to undef. I prefer this to a .key syntax.
OpenSCAD objects (discussed above) can be accessed using either obj.key or obj["key"] syntax. They are like JavaScript objects in that way.
Hello friends,
I am thinking why this very good software has not the associative arrays... (sorry vectors..) I found a lot of workarounds using some kind of search functions, e.g.: here or here.
What is currently working is that first three items from the array can be accessed by x,y,z indexes like:
So why we cannot access the any item by similar way?
I can imagine that the array can be specified by the following example (or something similar):
Then items might be accessible by normal numerical indexes or by "named indexes" So these variants will be equivalent:
And some nested arrays samples:
The array can be stored in memory by the same way as now with additional info which will allow to convert the "named indexes" to the numeric indexes - then Internally the item will be retrieved by numeric index as usually.
This can be very useful feature. What do you think?...