Jump to content

GetComponent in lua causes error (nil value)


Dreikblack
 Share

Go to solution Solved by Josh,

Recommended Posts

Tried:

GetComponent("Mover")
GetComponent(Mover)
GetComponent<Mover>()

 

This example also not working https://www.ultraengine.com/learn/Entity_GetComponent?lang=lua

require "Components/Motion/Mover"

--Get the displays
local displays = GetDisplays()

--Create a window
local window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[1], WINDOW_CENTER | WINDOW_TITLEBAR)

--Create a framebuffer
local framebuffer = CreateFramebuffer(window)

--Create a world
local world = CreateWorld()

--Create a camera
local camera = CreateCamera(world)
camera:SetClearColor(0.125)
camera:SetPosition(0, 0, -2)

--Create a light
local light = CreateBoxLight(world)
light:SetRotation(45, 35, 0)
light:SetColor(2)
light:SetRange(-5, 5)

--Create a model
local box = CreateBox(world)
box:SetColor(0,0,1)

--Add a component for automatic motion
local component = box:AddComponent(Mover)
component.rotationspeed.y = -2
box.mover.rotationspeed.x = 2

local componentTest = box:GetComponent("Mover")
if (componentTest ~= nil) then   
    Print("Success")
end

while window:KeyDown(KEY_ESCAPE) == false and window:Closed() == false do

    --Update the world
    world:Update()

    --Render the world to the framebuffer
    world:Render(framebuffer)

end

 

Link to comment
Share on other sites

  • 2 weeks later...

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...