I am using TNT Particle Engine by
@GregBUG, and I was wondering how I could "automate" the process of creating some particles.
I can save an array of "properties" with their respective values - like
myParticle = {
[setColor] = {20,20,255},
[setSpeed] = {10,50}
}
--and then call them out like this.
local particle = CParticles.new(particleGFX, 0,0,0,"add")
particle:setSpeed(unpack(myParticle.setSpeed))
particle:setColor(unpack(myParticle.setColor)) |
And this works.
May I "read" myParticle values in pairs and call the respective particle/CParticles method?
I made some tests, but the nearest I went was:
myParticle = {
[setColor] = {20,20,255},
[setSpeed] = {10,50}
}
local particle = CParticles.new(particleGFX, 0,0,0,"add")
local metat = getmetatable(particle)
for v, func in pairs(metat) do
print( v, func)
--[[ this print outputs "almost" what I think I need. I just get some methods out of all the available particle methods
setEnableAlphaMorphIn function: 0619ECCC
getAlphaMorphOutEnabled function: 0619EEAC
getSizeMorphOutEnabled function: 0619EE94
getColorMorphOutEnabled function: 0619EE7C
setEnableColorMorph function: 0619EC24
getMaxDelay function: 0619E9B4
setMaxLife function: 0619E96C
getAlphaMorphInEnabled function: 0619EE34
setSizeMorphOut function: 0619EB4C
getDirectionMorphOutEnabled function: 0619EE4C
setSize function: 0619EA5C
__new function: 061947C4
setEnableSpeedMorph function: 0619EC0C
getSizeMorphInEnabled function: 0619EE1C
setLoopMode function: 0619EA44
setGravity function: 0619EA74
getSpeedMorphInEnabled function: 0619EDEC
init function: 0619E920
getSizeMorphEnabled function: 0619EDA4
setSpeed function: 0619E9E4
]]
if myParticle[v] then
print_r(myParticle[v]) --this outputs exactly what I meant.
particle[v](unpack(myParticle[v])) --I tought this should work
end
end |
Here I get an error from TNT Particle Engine:
classes/tntparticlesengine.lua:1109: attempt to index local 'self' (a number value)
stack traceback:
classes/tntparticlesengine.lua:1109: in function '?'
while it was executing setSpeed (so it was "right") but line 1109 is on the wrong side of the if statement (since I provided MaxSpeed) - but This doesn't count, because I am not parsing the real "method table"/external API (how do i call it?).
I suppose I need some lua magic / guru support here: How do I get the "methods" table of a class instance?
I could follow the "bad" way of "if statements chain", but I can't believe that I can't do this with a for loop and all the wonders provided by lua
Thank you
Comments
Here it is:
particle.spec = particle["spec"]
particle:spec() = particle.spec(self)
I still can't get the "reference" to the methos of particle - and "how" do I call them?
The first parameter in the function particle:something() is self.
Change this line:
particle[v](unpack(myParticle[v])) --I tought this should work
To:
particle[v](self,unpack(myParticle[v])) --I tought this should work
Look at this attachment
At least I learned something new but i still get an error
--this is the output print_r of myParticle[v]
[1] => 50
[2] => 250
--then giderosplayer FC and gives the error:
classes/tntparticlesengine.lua:1105: attempt to index local 'self' (a nil value)
stack traceback:
classes/tntparticlesengine.lua:1105: in function '?'
Which is different from previous post, this time it happens in the right side of the if statement (in setSpeed() method, so I would think that your information was right).
However it seems that this is not exactly the same thing as calling it from
particle:setSpeed(unpack(myParticle[v]))
which works seamlessly
:-?
I think I would go for the "if chain" in my project, but this info bothers me from a scientific point of view
thank you for trying, but nope
classes/tntparticlesengine.lua:1105: attempt to index local 'self' (a function value)
stack traceback:
classes/tntparticlesengine.lua:1105: in function '?'
same error as before.
However, I should use a better "starting point" than particle metatable: it seems best to use my array.
let's recap, project attached if someone has a minute to share and try it out
particle:setSpeed(10,50) is the same as particle.setSpeed(particle,10,50).
Likes: pie
I was sure I tried it already, but maybe I did something wrong last time..
TNT Particle editor on its way..
Just copy it:
it works in my attachment.
myParticle = {
["setColor"] = {20,20,255},
["setSpeed"] = {10,50}
}
local particle = CParticles.new(particleGFX, 0,0,0,"add")
for property, values in pairs(myParticle) do
particle[property](self, unpack(values))
end
>-
thank you hgy29.