LUA passing parameters are coming messed up

Hello all,

im passing some values to a function.

I checked the values in shootParticle, very value is fine and right. Then im getting total wrong values passed to particle.shoot. I’m looking for my fault where i could imagien it, but i cant seem to find after 1 hour. Im not famiarly with scripting or LUA as I’m coming from more like Java, C#, C++, so i guess it might be fairly easy for a more experienced LUA programmer.

Example scenario:

shootParticle output: velocity.x = 200, velocity.y = -1200, target =2

particle.shoot output: velocity 796, velocity.y 1664, target=table:07C40770 ( i addded x and y for testing purposes to look if im getting more values than wanted: x = 2 (the target value here) and y = nil (ok no more value)

local function shootParticle(velocity, target) print("@spawner! velocity: " ..tostring(velocity.x) .. " " ..tostring(velocity.y) .. " target:" ..tostring(target)) shoot\_particle:shoot(velocity, target) spawnParticle() end particle.shoot = function(velocity, target, x, y)       print("@particel! velocity: " ..tostring(velocity.x) .. " " ..tostring(velocity.y) .. "    target:" ..tostring(target).. " look for more: "..tostring(x).." "..tostring(y))       particle:setLinearVelocity( velocity.x, velocity.y )       pipe = target end

I would appreciate every help/clue.

Change shoot_particle:shoot to shoot_particle.shoot

When you use “:” you’re implicitly passing a reference to the calling object as its first argument.

Another solution is to declare your function with “:” instead of “.” In that case you’ll have a implicit variable called “self” within the function which refers to the object making the call.

Thank you very much. This was exactly my fault.

Change shoot_particle:shoot to shoot_particle.shoot

When you use “:” you’re implicitly passing a reference to the calling object as its first argument.

Another solution is to declare your function with “:” instead of “.” In that case you’ll have a implicit variable called “self” within the function which refers to the object making the call.

Thank you very much. This was exactly my fault.