Variables
In this example, we will show you how to use the CreativeEditor SDK's CreativeEngine to modify variables through the variable
API. The variable
API lets you set or get the contents of variables that exist in your scene.
Setup#
This example uses the headless CreativeEngine. See the Setup article for a detailed guide.
To get started right away, you can also access the block
API within a running CE.SDK instance via cesdk.engine.block
.
Check out the APIs Overview to see that illustrated in more detail.
Functions#
findAll(): string[]
Get all text variables currently stored in the engine.
- Returns Return a list of variable names
setString(key: string, value: string): void
Set a text variable.
key
: The variable's key.value
: The text to replace the variable with.
getString(key: string): string
Set a text variable.
key
: The variable's key.- Returns The text value of the variable.
remove(key: string): void
Destroy a text variable.
key
: The variable's key.
referencesAnyVariables(id: DesignBlockId): boolean
Checks whether the given block references any variables. Doesn't check the block's children.
id
: The block to inspect.- Returns true if the block references variables and false otherwise.
Localizing Variable Keys (CE.SDK only)#
You can show localized labels for the registered variables to your users by
adding a corresponding label property to the object stored at
i18n.<language>.variables.<key>.label
in the configuration.
Otherwise, the name used in variable.setString()
will be shown.