Hey, I’m trying to set the iap_listener following the documentation. But I always get the following error:
"attempt to index global ‘iap’ (a nil value)"
What am I doing wrong?
Are you doing this from a GUI-script?
Nope, doing it from a regular script. Got it working now after about a week of try and error. I feel like the documentation is very bad at explaining everything.
I think I have figured out the following things thou:
The “attempt to index global ‘iap’ (a nil value)” will always happen when you build from the engine directly, sence i has no contact with any shop? (Still got the same error message but it works when I play it on an iphone)
You need a different listener for each purchase so that the current listener should match what you are trying to buy. And in the listener you decide what will happen if the purchase is successful.
The difference between a sandbox mode and the real deal is the provisioning profile used when built?
Are this correct or have I’ve gotten something wrong?
Yes. Iap only exist on devices. You can’t do it on desktop.
Do you need a different listener for each purchasable?
No. You can only add one transaction listener function via iap.set_listener(). All details of the transactions can be found in the value passed through the “transaction” argument.
What does the “transaction” hold for information? Haven’t found any documentation about this
The transaction table has the following members:
ident: product identifier
state: transaction state
trans_ident: transaction identifier (only set when state == TRANS_STATE_RESTORED or state == TRANS_STATE_PURCHASED)
receipt: receipt (only set when state == TRANS_STATE_PURCHASED)
date: transaction date
original_trans: original transaction (only set when state == TRANS_STATE_RESTORED)
is “transaction.ident” the same as the the product id (“com.palindrome.overgrown.xxx”)?
Or how should I check what product was bought with the transaction?
Yes, it contains the identifier for the purchase.