Quick question about node.findByTag


#1

I’m working on my Euclidean TRPG Assistant (ETA) (https://playcanvas.com/editor/scene/700970), and I want to reference one of my buttons from another script. I’ve tried giving the button a unique tag (rulerButton) and referencing it by using node.findByTag as specified in https://developer.playcanvas.com/en/api/pc.Entity.html#findByTag .

However, when I do this, it throws an error: “Uncaught ReferenceError: node is not defined”. Here is my script for reference:
https://playcanvas.com/editor/code/600366?tabs=17191804&line=81&col=34&error=true

Note that I’ve also tried findByName(“Ruler_Button”), but it falsely claims that no such name exists.

Any help with this, or advice on an easier way to reference the button, would be greatly appreciated.


#2

Just saw in the console log that it’s referring to the .onSelect function (in the same script). The only reason I could imagine that mattering is line 64, which refers to the rigidBody property. However, I have added both a rigidBody and a collision property to the ruler button.

It goes without saying that this has not resolved the problem.


#3

Hi That_Guy,

If you play the app and then bring up the debug tools ( in the case of Chrome, press F12 ), you get the following screen, showing that node isn’t defined.


#4

I know. I’m asking what that means, and what I can do about it.


#5

Instead of node.findByTag, try this.app.root.findByTag

This should let you get past the current issue.