Store transactionCallback within an object

I have created a settings.lua “object” that handles user preferences, game settings and handles in-app purchases. If I try and use a method for my store callback, it fails to pass the event. if I use a regular function then it works just fine.

I have shortened most of the code, but essentially, I have this:

local settings = {} local transactionCallback function settings:init() 1. --\> store.init("google", transactionCallback) 2. --\> store.init("google", settings.storeCallback) end function settings:purchaseApp() store.purchase({android.test.purchased}) end function settings:storeCallback(event) ..callback code.. end function transactionCallback(event) ..callback code.. end return settings{}

If i make my purchase and use the “transactionCallback”, everything works fine. if I use the “settings.storeCallback” the event isn’t passed.

I am just curious as to why this won’t work, or if there is a solution other than just using the regular callback method.

Thanks

it’s dot-notation versus colon-notation – you’ll find your event in the “self” parameter: print(self.phase) for example. several ways around it, but assuming you DO need an object:method call to access “self”, then maybe easiest?/clearest? might be a local closure, fe:

-- at your "2. --\>" local function onStoreInit(event) self:storeCallback(event) end store.init( "google", onStoreInit)

it’s dot-notation versus colon-notation – you’ll find your event in the “self” parameter: print(self.phase) for example. several ways around it, but assuming you DO need an object:method call to access “self”, then maybe easiest?/clearest? might be a local closure, fe:

-- at your "2. --\>" local function onStoreInit(event) self:storeCallback(event) end store.init( "google", onStoreInit)