Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

type vs _type for findObjs() -- both work?

1592940369
timmaugh
Pro
API Scripter
Is there some defaulting magic going on behind the scenes for the findObjs() function? I just realized that I have been sending a call to it like this: let foo = findObjs({ type: 'ability' , characterid: theSpeaker.id, name: "That thing" })[0].get("action"); ...and it finds the ability, even though the documentation for the Ability object says that the property is named "_type". Is this intended to work, or is this an unsupported UAYOR situation?
1592944102
GiGs
Pro
Sheet Author
API Scripter
It is intended to work. Attributes with _ at the start can be used with or without it. The _ signifies that its a special attribute that allows to you access the value more easily. That's not relevant in the above case, because you aren't reading the type property, but that's why it exists.
1592944839
timmaugh
Pro
API Scripter
Perrrrrrrrrrrrfect. Also, less creepily: perfect. Thanks!
1592947010
The Aaron
Roll20 Production Team
API Scripter
Minor clarification: The leading _ signifies a read only property.  You can try to set it, but it will silently ignore you.  _id is also promoted to .id as a convenience because every object has one and it is used so often. Opinion: You should always use the undecorated version.  It will always work and behaves the same way as if you had used the _.  In the case where a property becomes read-write, it will continue to work, whereas the decorated version will suddenly break.  Further, typing a _ is annoying, so if your editor supports tab completion, you will benefit from not bothering to type it.  There is only one case where you MUST use the _, and that is on events.  on('change:player:_online', ...) works, on('change:player:online',...) does not.