Scripts and How Events start them

Hello, all. A few questions about events that will run a script.

a. So events like “pointerdown” are pretty clear. But is there any documentations about when these events fire:

i. Ready/Notready – how does the system determine readiness/notreadiness? When do these fire?
ii. Seen/NotSeen – seems pretty straightforward, but do these fire every time an object is not within camera view? Does it fire when the object is invisible?

b. Running scripts from other scripts?
If I make a blank script, how can I call it from other scripts? That would seem to be the only reason to have a blank script, right?

c. .on method - multiple ones in one script

Recently, I wanted to start and end an action from the same script but using different buttons.
Can I put two items with the .on method into one script? When I try this, it does not even remotely work.


parent.on(“pointerdown”, (e) => {

starttheaction();

});

otherbutton.on(“pointdown”,(e)=> {

stoptheaction();

});

Hi,

b.
A blank script is also handy to put all yours scripts at the same place.
If you want to call a function from outside the script where it is declared, then use export

export function functionName(){ ... }

then call it by specifying its path:
symbol.nodes.myCode.functionName();

( If the function is declared inside the script ‘myCode’ )

c.
Again, you have just to specify the path of the objects receiving the event:

symbol.nodes.btn1.on("pointerdown", (e) => { ... });
symbol.nodes.btn2.on("pointerdown", (e) => { ... }); 

Cheers,

1 Like

Very cool. Thanks so much! I will try this.

May I ask, are script variable also exported, or do I have to do this explicitly?

Hi @donnav,

To expand on @jvouillon’s answer:

a) i. As unhelpful as it sounds, the ready event is fired when the object is ready to be used e.g. the video at the URL provided in a streaming video node has been successfully retrieved.

ii. The seen and notseen events aren’t fired by objects (3D models etc) but rather targets i.e. tracking images. These are fired when the tracking image enters and exits the device’s camera view, respectively.

b) A blank script in a project will prevent the experience from compiling. To pass data between scripts (functions, variables etc.) they need to be explicitly exported e.g. to access a variable from a different script it needs to be passed the export keyword when declared e.g. export let myVariable;.

You can find more information on subsymbol communication in ZapWorks Studio in this documentation article.

c) You can chain event handlers as necessary in your project. In your exmple, had you created a reference to the otherbutton node in the script you were trying to set up the pointerdown handler for?

Without a reference the script has no knowledge of the second node, so it won’t be able to listen out for an event fired by it. You can create a reference to a node by dragging it from the Hierarchy/Symbol Definitions/Media Library into the script.

Also, the second event handler is listening for "pointdown" instead of "pointerdown", so it’s also worth checking that the correct event is being listened out for.

Hope this helps.

All the best,
Seb