Set method for Map

Hi DO team,

Is it too much to ask for .Set(key, value) and maybe .Get(key) for Map objects, similar to Script.Vars? I want to use a linter with VSCode and they go crazy with the maps:

mymap(key) = value; // ESLint sees this as a syntax error and stops completely
// mymap.Set(key, value); // the tools have no problem with such lines
// mymap[key] = value; // same, no problem

JSHint & TSC also complain like ESLint and they are correct: it's not valid JS as it is. The statement is seen as trying to assign a RValue to RValue, i.e. syntax error. Vectors don't have this problem because myvector[index] = value is already valid JS, but Maps with the parantheses on the left hand side of an assignment breaks the tools. With either one of mymap.Set(key, value) or mymap[key] = value this won't happen.

Developing without a debugger is hard as it is and without a linter and similar tools, it becomes quite nerve-wrecking.

Thanks

1 Like

We'll add Set/Get methods in the next update. We'll also make it so that [] works in some cases - it will work with key names that begin with an underscore (e.g. map["_moo"]) , as well as completely numeric key names (e.g. map[123]).

The problem with using [] generally with our Map object is that Active Scripting doesn't distinguish between object.name and object["name"] at all. We have no way to tell which form has been used. This is fine for vectors which have numeric indices but maps use string keys, and so we felt this would be confusing and/or dangerous (e.g. imagine trying to use the string "clear" as a map key).

3 Likes

This is available now in 12.23.1 Beta.

1 Like

Hi @Jon

I tested the Get/Set methods successfully; not tried out the number or _ versions though. The switch from () calls to Get/Set was very smooth. You guys are the bomb!

Thanks a lot!

2 Likes