Hey guys!
So my skills are improving a little bit every day but there are still a couple of things that I'm a bit hazy on. One is around variable scoping, the other is about bump.
So here goes!
Let's say I have the following:
function GameScene:init()
GAME = self
myNumber = 7
self.myNumber = 7
GameScene.myNumber = 7
end
...
function GameScene:printMyNumber()
print(self.myNumber)
print(GameScene.myNumber)
end
function GameScene:handleSelf(randomObject)
print(self.myNumber) -- I gots nothin'!
print(GameScene.myNumber) -- I gots nothin'!
print(GAME.myNumber)
end |
So, I can't access self.myNumber if I'm passing in an argument to that last function. If I pass in self first though... Is that how you would do it in Lua? (Does that even work? I don't have access to my IDE right now.
)
On that note, is self.myNumber and GameScene.myNumber the same thing, or is GameScene.myNumber instantiating itself again? They usually have the same table address so I'd wager the former.
About bump (or cbump rather!), is there a way to show the physics in debug mode? Something like world:enableDebug or world:showPhysics? I edited one of the functions in bump before to show shapes but I wasn't able to update them every frame. It was semi-useful.
Comments
function GameScene:init()
GAME = self
myNumber = 7
self.myNumber = 7
GameScene.myNumber = 7
end
...
function GameScene:printMyNumber(self)
print(self.myNumber)
print(GameScene.myNumber)
end
function GameScene:handleSelf(randomObject)
print(self.myNumber) -- I gots nothin'!
print(GameScene.myNumber) -- I gots nothin'!
print(GAME.myNumber)
end
---------------
TEST1=GameScene.new()
TEST1:printMyNumber(TEST1)
or
print(TEST1.myNumber)
try this way
Likes: Astirian
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
function GameScene:printMyNumber(self)
is wrong and that
function GameScene:printMyNumber()
was good actually, or
function GameScene.printMyNumber(self)
is also good and means the same - notice the . instead of :
Likes: Astirian
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Of course this is a little messy because you need to add this code to all game objects and then when you release.. you have to comment out or remove all of that code.
Still, if you need it, then that's probably the best way I can think of at breakfast time
Likes: Apollo14, Astirian