Skip to main content

MTScript Data Functions

The following functions have been added to MapTool Macro Script to work with data. Currently, the only type of data stored is for Add-Ons, but this will be expanded in the future.

data.getStaticData
Usage:
data.getStaticData(
namespace
,
path
)
Parameters
  • namespace
    the namespace of the Add-On that the data is stored in
  • path
    The path to the file in the Add-On

If called from within code in the add-on then it will be able to access any file, otherwise it will only be able to access the files in the public/ directory. This can be used to access text files, JSON, or even images within the add-on. Images are returned in the asset:// format so they can be used in image tags.
Example

[r: data.getStaticData("com.example.myaddon", "mydir/myfile.txt")]

data.listTypes
Usage:
data.listTypes()

Lists the type of Data available.

Currently the only type is "addon:" but this will change in the future

data.listNamespaces
Usage:
data.listNamespaces(
type
)
Parameters
  • type
    The type of data to list

Returns a list of namespaces for the given data type.
Example

[r: data.listNamespaces("addon:")]

data.listData
Usage:
data.listData(
type
,
namespace
)
Parameters
  • type
    The type of data to list
  • namespace
    The namespace of the data to set

Returns a list of the data in the given namespace.
Example

[r: data.listData("addon:", "com.example.myaddon")]

data.setData
Usage:
data.setData(
type
,
namespace
,
name
,
value
)
Parameters
  • type
    The type of data to set
  • namespace
    The namespace of the data to set
  • name
    The variable name of the data to set
  • value
    The value to set

Sets the data to the specified value.
Example

[r: data.setData("addon:", "com.example.myaddon", "myVar", 1 )]

Things to note:

  • Unlike token properties data variables have a type (number, string, json etc), once set the type cannot be changed.
  • No conversion to/from string is required for JSON values so they are a lot faster than token and lib:token properties.
  • This data is shared between clients and persisted in the campaign just as token and lib:token properties are.
data.getData
Usage:
data.getData(
type
,
namespace
,
name
)
Parameters
  • type
    The type of data to get
  • namespace
    The namespace of the data to get
  • name
    The variable name of the data to get

Returns the specified data
Example

[r: data.getData("addon:", "com.example.myaddon", "myVar")]

Things to note:

  • Unlike token properties data variables have a type (number, string, json etc), once set the type cannot be changed.
  • No conversion to/from string is required for JSON values so they are a lot faster than token and lib:token properties.
  • This data is shared between clients and persisted in the campaign just as token and lib:token properties are.
data.removeData
Usage:
data.removeData(
type
,
namespace
,
name
)
Parameters
  • type
    The type of data to remove
  • namespace
    The namespace of the data to remove
  • name
    The variable name of the data to remove

Removes the specified data
Example

[r: data.removeData("addon:", "com.example.myaddon", "myVar")]

Things to note:

  • This data is shared between clients and persisted in the campaign just as token and lib:token properties are.