put this at the top of your code
io.output():setvbuf('no')
if testing on the devices view live output in xcode/organizer/console
if testing in the xcode/simulator view live output in applications/console
this does not work for me
local listOfProducts = {
"com.ezraanderson.item1",
"com.ezraanderson.item2",
"com.ezraanderson.item3",
}
set your products up this way for it to work.
local validProducts = {}
local invalidProducts = {}
local listOfProducts = {
"item1",
"item2",
"item3",
}
test your code like this
function unpackValidProducts()
print("valid"..#validProducts)
print("in-valid".. #invalidProducts)
for i=1, #validProducts do
print("validProducts = "..i..": ".. tostring(validProducts))
print("validProducts"..i..".title = " .. tostring(validProducts[i].title))
print("validProducts"..i..".description = " .. tostring(validProducts[i].description))
print("validProducts"..i..".price = " .. tostring(validProducts[i].price))
print("validProducts"..i..".productIdentifier = " .. tostring(validProducts[i].productIdentifier))
print("---------------------------")
end
end
function loadProductsCallback( event )
validProducts = event.products
invalidProducts = event.invalidProducts
unpackValidProducts ()
end
function setupMyStore (event)
store.loadProducts( listOfProducts, loadProductsCallback )
end
function storeTransaction( event )
local transaction = event.transaction
if transaction.state == "purchased" then
-- If store.purchase() was successful, you should end up in here for each product you buy.
local alert = native.showAlert( "Rapid Racer", "Transaction Successful!", { "OK"})
doSomethingHere()
elseif transaction.state == "restored" then
local alert = native.showAlert( "Rapid Racer", "Transaction restored (from previous session)", { "OK"})
elseif transaction.state == "cancelled" then
local alert = native.showAlert( "Rapid Racer", "User cancelled transaction", { "OK"})
elseif transaction.state == "failed" then
local alert = native.showAlert( "Rapid Racer", "Transaction failed!"..transaction.errorString, { "OK"})
--print("Transaction failed, type:", transaction.errorType, transaction.errorString)
else
local alert = native.showAlert( "Rapid Racer", "Unknown event", { "OK"})
end
store.finishTransaction( transaction )
end
use timer delay to start it
timer.performWithDelay (100, store.init() )
timer.performWithDelay (1000, setupMyStore() )
[import]uid: 89663 topic_id: 18067 reply_id: 72566[/import]