Accessing global map variables with evaluator or function?

Say I create some global map variable, potentially with nested maps like this example below. Would there be a way to retrieve the values from within the map variable in a standard function command?

function OnClick(clickData)
{
	// Create empty map variables
	var testOuterMap = DOpus.Create.Map();
	var testInnerMap = DOpus.Create.OrderedMap();

	// Set arbitrary value for key/value for inner map, then put inner map into outer map
	testInnerMap.Set("WhateverKey", "Example String");
	testOuterMap.Set("InnerMap", testInnerMap);

	// Also create string key/value in outer map
	testOuterMap.Set("SomeString", "Some Test String");

	// Create testMapGlobal global variable using outer map
	DOpus.vars.set("testMapGlobal", testOuterMap);
}

So the structure of the variable is basically:

testMapGlobal :
    ⤷ { SomeString : "Some Test String" }
    ⤷ InnerMap : 
         ⤷ { WhateverKey : "Example String" }

To get the value back with jscript it would just be like this for example:

// ------ Test Retrieving value from global -----------
var retrievedOuterMap = DOpus.vars.get("testMapGlobal");
var retrievedInnerMap = retrievedOuterMap.Get("InnerMap");
var retrievedValue = retrievedInnerMap.Get("WhateverKey");

// Output value in a few possible ways
DOpus.Output(retrievedValue);
DOpus.Output(retrievedInnerMap.get("WhateverKey"));
DOpus.Output(retrievedInnerMap("WhateverKey"));

DOpus.Output(retrievedOuterMap("SomeString"));

I tried to do something like this in a user command but it doesn't work and I couldn't figure out if it's even retrieving the map as a map object:

@Set TestMap={$glob:testMapGlobal}

@Output Value Using Function1: {$TestMap("SomeString")}
@Output Value Using Evaluator1: {=$TestMap("SomeString")=}

@Output Value Using Function2: {$glob:testMapGlobal("SomeString")}
@Output Value Using Evaluator2: {=$glob:testMapGlobal("SomeString")=}

@Output Type Using Evaluator1: {=TypeOf($TestMap)=}
@Output Type Using Evaluator2: {=TypeOf($glob:testMapGlobal)=}

I don't think you can access them directly. The maps are scripting objects, so only scripts can use them.

One way would be to have a script add-in which adds a command that can be told which map/key to get the value of, and then set it in a temporary variable which could be use in a command or Evaluator code (as long as the result is a simple number/string). But that probably isn't better in many situations compared to using some script code directly instead of a simple command or Evaluator code.

Ah ok maybe I'll do a helper add-in script then

1 Like