You can get a list of an object's member properties and functions that you can access from script by selecting an object and pressing the F1 key on your keyboard.
As a general rule, property naming conforms to what is seen in the Property Editor panel. For instance, here's how we change the following properties of a MeshEntity in script:
function Trigger:onEnter(obj)
obj.active = true
obj.castsShadows = true
obj.color = rgba(255,0,0)
end
Notice the general rule regarding upper-vs-lower case, the member's first word's first letter is always lower case but the remaining words start with upper case (e.g. 'castsShadows'). This is referred to as camel case.
Other times, the property we need to access may live in a child attribute of an object. For instance, let's say we have a NumberSignalController controlling the radius of a Sphere:
Here's how we can access it from the root MeshEntity:
function MeshEntity:onMove()
signal_controller = self:getMeshModel():getShape():getRadiusProperty():findAttribute("NumberSignalController")
signal_controller.amplitude = self:getWorldPosition().y
end
Notice that we access the 'Radius' property as an object via 'getRadiusProperty' instead of as a value via '.radius' (which would be 0.2753 in the above example). This is important as the property object allows us to call 'findAtrribute' on it to search its child attributes.
Here's another example of accessing child attributes, in this case the 'RigidBody':
function MeshEntity:onPress()
self:getRigidBody():applyCentralImpulse(vector3(0,2,0))
end
The above example will make the object hop. Note that this function uses 'getRigidBody()' which is a specialized shortcut for 'self:findAttribute("RigidBody")'. It's specialized due to its common use.
Comments
0 comments
Please sign in to leave a comment.