Having an array as a composer variable

I really like the composer api and it makes menus and cut scenes extremely easy to implement. I find myself using the composer. get and set variable occasionally and this is great for boolean for int values but is it possible to have an array (table) as your composer variable? Lets say my game has 4 worlds and 8 levels for each world. I want to be able to send from scene to scene an array like: levelsComplete[]= {8,5,3,1} each index of the array represents a world number and the numbers in the table represent the number of levels completed.
 

It does not seem likely because the arguments for the setvariable are string and then value… but who knows.

Hope it’s possible because that would be very powerful. There are of course a couple ways I can think about getting around this but I would rather go through composer.

Thanks in advance.

Hi @patrickaaronmoore,

Yes, tables (arrays) should work fine with Composer variables. I believe internally that they are set as a key-value pair, so the string “variableName” that you give it during .setVariable is the key, and “value” is the value, which can be a table or whatever.

Take care,

Brent

Perfect. Just tried it and it works.

For anyone else who wants to use this::
to set up:
composer.setVariable(“levComp”, {1,2,4,5})

and to call it’s simply:

composer.getVariable(“levComp”)[3]

this will return 4.

Thanks!
 

Hi @patrickaaronmoore,

Yes, tables (arrays) should work fine with Composer variables. I believe internally that they are set as a key-value pair, so the string “variableName” that you give it during .setVariable is the key, and “value” is the value, which can be a table or whatever.

Take care,

Brent

Perfect. Just tried it and it works.

For anyone else who wants to use this::
to set up:
composer.setVariable(“levComp”, {1,2,4,5})

and to call it’s simply:

composer.getVariable(“levComp”)[3]

this will return 4.

Thanks!