Jump to content

Accessing an Emitter interface in LUA script problem


Rozen Software
 Share

Recommended Posts

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)

Link to comment
Share on other sites

Works fine for me. Are you sure that the emitter is the only child? I suggest performing an entity:CountChildren() to confirm.

post-14-0-46331100-1428259433.jpg

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.

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

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

Link to comment
Share on other sites

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

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

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