Rozen Software Posted April 5, 2015 Share Posted April 5, 2015 I have created an entity with one emitter child object. I try to access its interface with the code: local emitter = self.entity:GetChild(0) emitter:Reset() Unfortunately Reset method is not executed and a nil value is thrown. Does someone know how to correctly access an Emitter interface from LUA script in such situation? Is this possible? Thanks, Piotr (Leadwerks 3.5 beta branch, Standard Edition) Quote Link to comment Share on other sites More sharing options...
macklebee Posted April 5, 2015 Share Posted April 5, 2015 Works fine for me. Are you sure that the emitter is the only child? I suggest performing an entity:CountChildren() to confirm. example code: function Script:UpdateWorld() local window = Window:GetCurrent() if window:KeyHit(Key.Up) then local emitter = self.entity:GetChild(0) emitter:Reset() emitter:SetColor(math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255,1) end end Also, remember there are several ways to access the emitter. You could use entity:FindChild() to search for the emitter's specific name. Or make it a script entity property in the property panel and drag the emitter to the textbox. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Rozen Software Posted April 5, 2015 Author Share Posted April 5, 2015 Yes, I checked it out and entity:GetCountChildren() returned 1. In my case this entity (your chamferbox) is a prefab and loaded dynamically. I did workaround it by attaching a script to the emitter entity: function Script:Reset() self.entity:Reset() self.entity:Play() end and invoking it: self.emitter = self.entity:GetChild(0) self.emitter.script:Reset() That's works ... Quote Link to comment Share on other sites More sharing options...
macklebee Posted April 5, 2015 Share Posted April 5, 2015 Ah - ok... you are loading it dynamically - that information you left out in the OP. Then in that case you have to cast the emitter to the Emitter class. It's probably best to get in the habit (myself included) to cast special entities after using GetChild or FindChild. This example works now even when the chamfer box is loaded dynamically via code: function Script:UpdateWorld() local window = Window:GetCurrent() if window:KeyHit(Key.Up) then local emitter = self.entity:GetChild(0) tolua.cast(emitter, "Emitter") emitter:Reset() emitter:SetColor(math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255,1) end end Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
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.