Pleca Posted November 24 Share Posted November 24 Hello everyone. How can I access light methods in a Component script attached to a light? I created a Point Light in the editor and attached a simple Component script to it. When I tried to use the light method GetRange() on the entity, it threw an error. What am I doing wrong? Simple Component script: Range = {} Range.name = "Range" Range.currentRange = Vec2(0, 0) function Range:Start() self.currentRange = self.entity:GetRange() end RegisterComponent ("Range", Range) return Range JSON file: { "component": { "properties": [ { "name": "currentRange", "label": "Range", "value": [0.0,0.0] } ] } } Error: Quote Link to comment Share on other sites More sharing options...
Solution Dreikblack Posted November 24 Solution Share Posted November 24 You need to cast self.entity to light, Something like: local light = (Light)self.entity self.currentRange = light:GetRange() 1 Quote Link to comment Share on other sites More sharing options...
Pleca Posted November 24 Author Share Posted November 24 Thanks for your reply. Amazing! You pointed me in the right direction. Thank you very much! For anyone who might need this in the future, the correct Lua syntax for casting is: local light = Light(self.entity) self.currentRange = light:GetRange() 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.