Can't seem to get "createComponent" to work

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Can't seem to get "createComponent" to work

Post 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?
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Can't seem to get "createComponent" to work

Post 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.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: Can't seem to get "createComponent" to work

Post 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.
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Can't seem to get "createComponent" to work

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