How to access variables and entity attributes in amazon Sumerian

223 Views Asked by At

I need help with a few things with Amazon Sumerian:

  • How can I access an entity's attribute in a script?
  • How can I access a variable from another script?

This is the code I tried to access an entity's variable that I set in the state machine but it returns undefined.

    function setup(args, ctx) {
       ctx.runButton = ctx.world.by.name('RunButton').first();
       console.log(ctx.runButton.getAttribute('isReset'));
    }
1

There are 1 best solutions below

0
On

You are using the correct method (<entity>.getAttribute()), but at the time setup() is called your state machine won't have actually been started. Try putting that code in your update() method and see if you get a different result.

For you second question, can you explain a bit more about what you mean when you say "access a variable from another script"?