trialing the OO concepts but have two questions I’m stuck on:
QUESTION 1
* Why do the use of colon (":") in the two places below “group:endLoadingPeriod” not work, and I have to change this to “.” to work? From an OO point-of-view shouldn’t this really be a colon?
* Note the error is “function arguments expected near ‘,’” on the “performWithDelay” line
QUESTION 2
* Why do I get an error with the line “self.hitPoints = hitPoints”?
* Error is “attempt to index local ‘self’ (a number value)”
Skydiver = {}
function Skydiver:new()
local group = display.newGroup()
-- Add Skydiver
local diver = display.newImage("scenes/splash/images/parachutist.png")
physics.addBody(diver)
group:insert(diver)
-- Remove Skydiving after period
function group:endLoadingPeriod( event ) -- QUESTION 1
group:removeSelf()
end
group.loadingTimer = timer.performWithDelay( 3000, group:endLoadingPeriod, 1 ) -- QUESTION 1
-- Sample Public Method
function group:setHitpoints(hitPoints)
print ("group:setHitpoints")
self.hitPoints = hitPoints -- QUESTION 2
end
return group
end
return Skydiver
Background I’ve been following is: http://jessewarden.com/2011/10/lua-classes-and-packages-in-corona.html [import]uid: 140210 topic_id: 25121 reply_id: 325121[/import]