Unexpected Behavior for Dictionary Includes Method

I have a GUI with some points where I want functions to be evaluated. The .drawFunc_({ is translating the Pen object and once the drawings reach these points I need them to do a specific action based on which way the object was being translated and a few other factors.

I noticed that I cannot seem to make an array of points though for conditional execution and I’m not sure what the problem is. The dictionary returns correctly, but the boolean is always returning false.

I would expect this to return true but it does not.

(
var scale = 2;
n = Dictionary.newFrom([
"1A" -> ( 5 @ 29 * scale),
"1B" -> ( 45 @ 29 * scale),
"1C" -> ( 93 @ 29 * scale),
"1D" -> ( 117 @ 29 * scale),
"1E" -> ( 165 @ 29 * scale),
"1F" -> ( 205 @ 29 * scale),

"2A" -> ( 5 @ 61 * scale),
"2B" -> ( 45 @ 61 * scale),
"2C" -> ( 69 @ 61 * scale),
"2D" -> ( 93 @ 61 * scale),
"2E" -> ( 117 @ 61 * scale),
"2F" -> ( 141 @ 61 * scale),
"2G" -> ( 165 @ 61 * scale),
"2H" -> ( 205 @ 61 * scale),

"3A" -> ( 5 @ 85 * scale),
"3B" -> ( 45 @ 85 * scale),
"3C" -> ( 69 @ 85 * scale),
"3D" -> ( 93 @ 85 * scale),
"3E" -> ( 117 @ 85 * scale),
"3F" -> ( 141 @ 85 * scale),
"3G" -> ( 165 @ 85 * scale),
"3H" -> ( 205 @ 85 * scale),

"4A" -> ( 69 @ 110 * scale),
"4B" -> ( 93 @ 110 * scale),
"ghostStart" -> ( 105 @ 110 * scale),
"4C" -> ( 117 @ 110 * scale),
"4D" -> ( 141 @ 110 * scale),

"5A" -> ( 45 @ 134 * scale),
"5B" -> ( 69 @ 134 * scale),
"5D" -> ( 141 @ 134 * scale),
"5E" -> ( 165 @ 134 * scale),

"6A" -> ( 69 @ 158 * scale),
"6B" -> ( 141 @ 158 * scale),

"7A" -> ( 5 @ 181 * scale),
"7B" -> ( 45 @ 181 * scale),
"7C" -> ( 69 @ 181 * scale),
"7D" -> ( 93 @ 181 * scale),
"7E" -> ( 117 @ 181 * scale),
"7F" -> ( 141 @ 181 * scale),
"7G" -> ( 165 @ 181 * scale),
"7H" -> ( 205 @ 181 * scale),

"8A" -> ( 5 @ 205 * scale),
"8B" -> ( 21 @ 205 * scale),
"8C" -> ( 45 @ 205 * scale),
"8D" -> ( 69 @ 205 * scale),
"8E" -> ( 93 @ 205 * scale),
"8F" -> ( 117 @ 205 * scale),
"8G" -> ( 141 @ 205 * scale),
"8H" -> ( 165 @ 205 * scale),
"8I" -> ( 189 @ 205 * scale),
"8J" -> ( 205 @ 205 * scale),

"9A" -> ( 5 @ 229 * scale),
"9B" -> ( 21 @ 229 * scale),
"9C" -> ( 45 @ 229 * scale),
"9D" -> ( 69 @ 229 * scale),
"9E" -> ( 93 @ 229 * scale),
"9F" -> ( 117 @ 229 * scale),
"9G" -> ( 141 @ 229 * scale),
"9H" -> ( 165 @ 229 * scale),
"9I" -> ( 189 @ 229 * scale),
"9J" -> ( 205 @ 229 * scale),

"10A" -> ( 5 @ 253 * scale),
"10B" -> ( 93 @ 253 * scale),
"10C" -> ( 117 @ 253 * scale),
"10D" -> ( 205 @ 253 * scale),
]);

n.includes(5 @ 253 * scale);
)

I figured out that if I change this to an array of variables instead of a dictionary, the boolean works if I use the variable name, but not the value. How can I work around this?

includes uses an identity check.

You need an equality check.

a = Point(3, 4);
b = Point(3, 4);

a === b  // identity test: false

a == b  // equality test: true

Solution: Use includesEqual.

hjh

Your syntax for using Dictionary.newFrom shouldn’t use ->. This returns true:

(
var scale = 2;
n = Dictionary.newFrom([
"1A", ( 5 @ 29 * scale),
"1B", ( 45 @ 29 * scale),
"1C", ( 93 @ 29 * scale)
]);
n.includes( 5 @ 29 * scale);
)
1 Like

Thanks, I ended up keeping these nodes as variables and not using a dictionary. Less typing in the end