Jump to content

Light with Component (Lua)


Pleca
 Share

Go to solution Solved by Dreikblack,

Recommended Posts

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:

photo_2024-11-23_21-29-22.png

Link to comment
Share on other sites

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()

 

  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...