"First Seen" in scripting vs actions

I’m using “first seen” to launch some elements when (and only when) a target image is first detected. I can do this with Actions but not with Scripting.

Here’s a simple example using Actions. A red plane appears on first seen; a green box appears on seen. Both red and green disappear when not seen. Therefore:

  • When target is first seen, BOTH appear
  • When target is lost, BOTH disappear
  • When target is seen the second time, ONLY the green box appears.
    FirstSeen_WithActions_WORKS.zpp (233.3 KB)

I can’t figure out how to do this with Scripting; I haven’t managed to locate documentation on how to implement “first seen” in the code. Mostly, I’ve tried substituting “first seen” or “firstseen” where I would have put “seen” or “notseen” in other code. So far, no luck:
FirstSeen_WithScripts_DOESNT_WORK.zpp (233.2 KB)

Can anyone help me integrate what seems like straightforward functionality into my code? I think it must be quite simple, but multiple attempts continue to fail… Thanks.

Solved my own question!

instead of parent.on(etc etc) I needed to make it parent.one(etc etc) as documented here and here.

Thus a version with functioning scripts: FirstSeen_WithScripts_FIXED.zpp (233.2 KB)

1 Like

Exactly that @benubyu! Well solved :slight_smile:

one will fire an event once, and only once. You can do the same with any event, for example, you can do parent.one("pointerdown, (e) =>{ //code here }); to run a pointer down event only the first time the parent node is tapped.

George