In-App Purchase
PURCHASE NEW · PURCHASE RESTORE · purchase · purchases
PURCHASE NEW
Buy a product: opens the store’s purchase and waits; the purchase event reports how it went.
PURCHASE NEW product
purchase_new(product)
Parameters
- product AS STRING - The product’s id.
Example
SCREEN 320, 240
FUNCTION on_purchase(result)
PRINT "purchase:", result
END FUNCTION
CALL EVENT on_purchase, "purchase"
IF purchase.available
PURCHASE NEW "remove_ads"
ELSE
PRINT "no store to buy from"
END IF
Notes
It’s also the function purchase_new, for when you want what it gives back.
PURCHASE RESTORE
Restore the products this user bought before.
PURCHASE RESTORE
purchase_restore()
Example
SCREEN 320, 240
// Give back what this player bought on another device; the "purchase" event reports each one
PURCHASE RESTORE
PRINT "asked the store to restore"
Notes
It’s also the function purchase_restore, for when you want what it gives back.
purchase
Pseudo-variable providing access to purchase product properties. AVAILABLE is always accessible and indicates whether IAP is connected to a provider (1) or offline/unavailable (0). Other properties (ID, NAME, DESCRIPTION, PRICE, PURCHASED) are populated during a FOR PURCHASE loop and read from the locally cached product list. Outside of a FOR PURCHASE loop, these loop-specific properties return empty/zero values. Note: PURCHASED only applies to non-consumable products (e.g., ‘remove ads’, ‘premium upgrade’). Consumable products (e.g., coins, gems) always show PURCHASED=0 since they can be bought multiple times - use the purchase event to track consumable inventory in your own game variables.
purchase
Example
SCREEN 320, 240
IF purchase.available
PRINT "the store is open"
ELSE
PRINT "no store here"
END IF
purchases
What the store has for sale: each with id, name, description, price and whether it is purchased.
purchases
Example
SCREEN 320, 240
FOR item = PURCHASES
PRINT item.name, item.price, item.purchased
END FOR
PRINT "the store has", LEN(PURCHASES), "items"