call to save data fails silently from transactionCallback

I have combined the tab demo and iap demo so that my first tab has functionality and the second tab is a store.

The load product call back and transactionCallback remain on the main.lua so that they can be called immediately and are listening for any callbacks.

Everything appears to work correctly. The store loads the items, clicking buy registers the sale and the transactionCallback is called but for some reason when I try to save the data it stops and no error is generated.

Here is some sample code....
--main.lua
local saveloaddata = require("saveloaddata")
if event.transaction.state == "purchased" then
print("Purchased start")
infoString = "Transaction successful!"
print (infoString)
descriptionArea.text = infoString
saveloaddata.addProduct(event.transaction.productIdentifier)
print("Purchased end")

--saveloaddata.lua
function addProduct( id )
print("Adding Product:" .. id)
_G.productsOwned[id] = "1"
saveData(id)
end

In the log I see "Purchased Start" & "Transaction successful!" but then nothing. I never see "Adding Product" or "Purchased end"

It works correctly from the simulator where I call the same "addProduct" function as soon as the button is clicked.

function newBuyButton (index)
-- Handler for buy button
local buttonDefault = "buttonBuy.png"
local buttonOver = "buttonBuyDown.png"
local buyThis = function ( product )
print ("Ka-ching! Purchasing " ..product)
-- Purchase the item
if isSimulator then
saveloaddata.addProduct(product)
else

It doesn't help that there are no errors or anything in the console giving some hint to what might have gone wrong.

Can anyone suggest anything that might help me fix or work around this problem.

s.

Ok I worked this out for anyone getting a similar problem. The problem is the descriptionArea.text. Once I removed that line it work as expected. I guess since the call back fires when I'm on another screen it doesn't exist any more.

views:1772 update:2011/10/10 21:27:38
corona forums © 2003-2011