Hi,
when a collision occures i want to check if one of the bodys is "activated". Activated is a local variable in the Object class:
self:body.activated = true -- for example |
Here is the OnBeginContact function:
function onBeginContact(event)
local fixtureA = event.fixtureA
local fixtureB = event.fixtureB
local bodyA = fixtureA:getBody()
local bodyB = fixtureB:getBody()
print("begin contact: " .. bodyA.type .. " & " .. bodyB.type)
if bodyA.type and bodyA.type == "Trigger" and bodyB.aktiviert == true then
bodyA.aktiviert = true
end
if bodyB.type and bodyB.type == "Trigger" and bodyA.aktiviert == true then
bodyB.aktiviert = true
end
end |
bodyA.aktiviert (or BodyB.aktiviert) is nil because its a local in the object class. But how to solve this??
An object shall only be activated if the touching object is already activated...
daniel303
Comments
Dislikes: BigWinston
This is the init of the PuckClass in puck.lua:
However, looking at it again it looks like your problem is trying to compare aktiviert to true since it might be nil maybe? The class you showed, shows aktiviert always being initialized and the type is always "Puck" for the body. Does its type get changed to "Trigger" at some point or is there a different class/body?
If aktiviert being nil is what throws the error then I suggest changing any check on aktiviert, to the following:
Yes, the problem is that aktiviert is nil. But it should be true in case Puck is the collision partner.
Should i post more of my code?
If you change the code similar to like what I said in my last post your code should function even if the value IS nil however because nil will be treated as a false if you take away the "== true".
But all in all you should be able to access it like that, there should be no problem
@ zvardin: thx a lot for this advise! I forgot the walls they are there too.
@atilim: THX! This brought the answer! It was the small mistake initializing the aktiviert property.. i wrote "aktivert" 8-|
I still dont understand why i can work with aktiviert here. Isn't it a local in the object class? But it is working. Thx a lot!!
it is easier to use words that can be spelled, so aktiv or active would have been easier/simpler.
just my $0.02 on naming variables
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
@OZApps: You're right. "aktiviert" is just the german word for "is active" ">
I'm really happy to work with gideros now. I used corona before. No forum access and the APK was very slow on device. I've read a lot about this problem with corona. But maybe it was my fault. Anyway gideros is better.