Pleca Posted November 24, 2024 Posted November 24, 2024 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
Solution Dreikblack Posted November 24, 2024 Solution Posted November 24, 2024 You need to cast self.entity to light, Something like: local light = (Light)self.entity self.currentRange = light:GetRange() 1 Quote
Pleca Posted November 24, 2024 Author Posted November 24, 2024 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
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.