Page 1 of 1
Can't seem to get "createComponent" to work
Posted: Sat Nov 01, 2014 1:18 am
by MrChoke
I see GamewObjects get the method createComponent. I cannot get it to work. I keep getting runtime errors on my 1st parameter. My code:
Code: Select all
c = torch_holder_1:getComponent("socket")
print(c) -- Works, get a table
torch_holder_1:removeComponent("socket")
c = torch_holder_1:getComponent("socket")
print(c) -- Works, get nil
torch_holder_1:createComponent("socket") -- ERROR. "socket X"
Anyone get this to work?
Re: Can't seem to get "createComponent" to work
Posted: Sat Nov 01, 2014 1:33 am
by Prozail
Code: Select all
function cTest()
c = torch_holder_1:getComponent("socket")
print(c) -- Works, get a table
torch_holder_1:removeComponent("socket")
c = torch_holder_1:getComponent("socket")
print(c) -- Works, get nil
torch_holder_1:createComponent("Socket")
c = torch_holder_1:getComponent("socket")
print(c) -- Works, get a table
end
it's stupid, but.... the class is case-sensitive on create... and ofc you need to set all the other parameters again afterwards.
Re: Can't seem to get "createComponent" to work
Posted: Sat Nov 01, 2014 1:49 am
by MrChoke
Prozail wrote:Code: Select all
function cTest()
c = torch_holder_1:getComponent("socket")
print(c) -- Works, get a table
torch_holder_1:removeComponent("socket")
c = torch_holder_1:getComponent("socket")
print(c) -- Works, get nil
torch_holder_1:createComponent("Socket")
c = torch_holder_1:getComponent("socket")
print(c) -- Works, get a table
end
it's stupid, but.... the class is case-sensitive on create... and ofc you need to set all the other parameters again afterwards.
Ack!! Yup that was it. Capitals on create and lower-case on get. Man, how did you guys figure that out! Thanks.
Re: Can't seem to get "createComponent" to work
Posted: Sat Nov 01, 2014 9:03 am
by Prozail
My very uneducated guess tells me that, "socket" (lowercase) is the instance name, whereas "Socket" is actually the classname where the "Component" part of "SocketComponent" gets removed by convention.
i would guess...