Prime31 Plugins – Javascript!!!!

I love Prime31 plugins and have used quite a few. I was very nervous about using them since my program, Puzzling Cubes, is in javascript. With all the forum help and the plugins I was able to add inapp purchase and flurry for google/amazon/apple in about 10 hours. Next time it will take me about 30 minutes. I did each of the versions in different projects(haven’t tried mixing them together yet)

I thought it would be handy for me to post a few of the key code headers for other to use.

This will cover iOS – inApp, flurry, Android – Google/Amazon inApp and flurry plugins.

iOS – flurry – implementation is very easy
- download program from asset store or directly from prime31
- install package, easy!

add this code to startup flurry(I put it in my start function on my menu page) – only issue is you get a warning if you call startsession more then once. Also, after importing package, build from build settings screen(new build) in order for prime to do its import magic in xcode.

// starts up flurry
FlurryBinding.startSession( “your app key from flurry”);
// sends off event – could be called anything
FlurryBinding.logEvent(“Started Session”, false );
// not sure this is needed, but it works well
FlurryBinding.setSessionReportsOnCloseEnabled( true );

add events throughout your program
FlurryBinding.logEvent(“your event 1″,false);

Android Flurry – start function – menu again
// start up flurry
FlurryAndroid.onStartSession(“your app key from flurry”,false,false);
// sends off event
FlurryAndroid.logEvent(“A Started Session”);

// also need exit to tell flurry to upload data – put this where your program will exit – I end session and restart when I switch scenes and when I exit program – home button code

inApp purchases

iOS First – download/import package
- drag StoreKitManager prefab into your opening scene
- optionally I add the listener script from the test scene to the prefab for debugging

each of my game scenes where I need in apps i put these in start function

// my products
var listProducts = new String[3];

listProducts[0] = “net.gordonroberts.xx”;
listProducts[1] = “”;
listProducts[2] = “net.gordonroberts.xxxx”;
//Listen for product list
StoreKitManager.productListReceivedEvent += productListReceived;
//listen for purchase
StoreKitManager.purchaseSuccessfulEvent += purchaseSuccessful;
//Request product list

//function to receive product list

function productListReceived(aProducts:System.Collections.Generic.List.<StoreKitProduct>){

for (var i = 0; i < 3; i++) {
print (aProducts[i].formattedPrice);
} else {
print(“product list empty”);
// verify you received the right products, in my case I check aProducts.count=3

// okay, lets buy product 1
// check if they can first
// someone bought something
function purchaseSuccessful(aPurchase : StoreKitTransaction){

if(aPurchase.productIdentifier == listProducts[0]){
// do something based on buy product 1
if(aPurchase.productIdentifier == listProducts[1]){
// do something based on buy product 2
if(aPurchase.productIdentifier == listProducts[2]){
// do something based on buy product 3

// Restore – only other thing you have to worry about is if someone wants to restore an item – I tie this to a restore button

// only other gotcha – unsubscribe to listening events when you leave your scene
StoreKitManager.productListReceivedEvent -= productListReceived;
StoreKitManager.purchaseSuccessfulEvent -= purchaseSuccessful;


Amazon – only covering code, not how to test it out, lots of docs on that on prime31′s site or amazons

– download and install package from Amazon Dev site – at this time their is an error in their build, it uses inapt api 1.0.5, but you need to use 1.0.3, probably fixed before you read this

put AmazonIAPManager prefab in your first scene, add listener script for test scene if you want

// i use this in each scene that needs inapps
var listProducts = new String[3]; // in initial var declarations

listProducts[0] = “net.gordonroberts.x”;
listProducts[1] = “net.gordonroberts.xx”;
listProducts[2] = “”;
//listen for amazon data items
AmazonIAPManager.itemDataRequestFinishedEvent += productListReceived;
AmazonIAPManager.itemDataRequestFailedEvent += productListNotReceived;
AmazonIAPManager.purchaseSuccessfulEvent += purchaseSuccessful;
AmazonIAPManager.purchaseUpdatesRequestSuccessfulEvent += restoreProducts;

// request amazon data items

// restore previous purchases(automatic restores so I make sure I watch for this on startup
function restoreProducts(revoked:System.Collections.Generic.List.,aPurchase : System.Collections.Generic.List.){
if(aPurchase[0].sku == listProducts[2]){
//do something – in my case product[2] is the only non-consumable that can be restored

function productListNotReceived(){
//print(“no product list received”);

function productListReceived(notFound:System.Collections.Generic.List.,aProducts:System.Collections.Generic.List.){

// verify your products list – I check for item count aProducts.count == 3
for (var i = 0; i < 3; i++) {
print (aProducts[i].price);
} else {
print(“product list empty”);

// buy something

// something was bought

function purchaseSuccessful(aPurchase : AmazonReceipt){

if(aPurchase.sku == listProducts[0]){
// do something for product 1
if(aPurchase.sku == listProducts[1]){
// do something for product 2
if(aPurchase.sku == listProducts[2]){
// do something for product 3

make sure an unsubscribe when leaving scene
AmazonIAPManager.itemDataRequestFinishedEvent -= productListReceived;
AmazonIAPManager.itemDataRequestFailedEvent -= productListNotReceived;
AmazonIAPManager.purchaseSuccessfulEvent -= purchaseSuccessful;
AmazonIAPManager.purchaseUpdatesRequestSuccessfulEvent -= restoreProducts;

// inapp purchase google

download/install package
copy prefab IABAndroidManager into startup scene, add listener script if you want

// in each scene that needs inapps – in start function
var listProducts = new String[3]; // initial var declarations

listProducts[0] = “net.gordonroberts.x”;
listProducts[1] = “net.gordonroberts.xx”;
listProducts[2] = “”;

IABAndroidManager.billingSupportedEvent += productListReceived;
IABAndroidManager.purchaseSucceededEvent += purchaseSuccessful;
IABAndroid.init(“public key from google”);

function productListReceived(aProducts: boolean){
// you have access to products, but no real info – sucks!!!!

// buy something

// item was purchased
function purchaseSuccessful(aPurchase:String,payload:String){

if(aPurchase == listProducts[0]){
//do something for purchase 1
if(aPurchase == listProducts[1]){
//do something for purchase 2
if(aPurchase == listProducts[2]){
//do something for purchase 3


// restore item

// unsubscribe to listening items when leaving scene
IABAndroidManager.billingSupportedEvent -= productListReceived;
IABAndroidManager.purchaseSucceededEvent -= purchaseSuccessful;

Tanks and Turrets – 2 years

I always wanted to make games. Early in junior high on my IBM pc jr I hacked away at a stock market emulator/game. Fast forward 30 years later and technology has got to the point that a fairly poor programer can produce a pretty decent game.

I work full time as an engineer. The last two years as a hobby I have been writing iOS games. My first game, Tanks and Turrets, was release 2 years ago. My goal was to see if I could actually publish something and make a little money along the way.

How did I do????

Tanks and Turrets – just over 100K downloads and $11,000 revenue on iOS

My friend ported it to Android and has around 200K downloads and also around $10,000 in revenue.

Not quit your job money, but we calculate we put about 400 hours into the two versions, that comes in around $50/hour.

The most interesting stat, the iOS version had 2000 downloads, 100K ad impressions and $7/day revenue last month(2 years after launch).

After writing the game engine the next two games, Tanks and Turrets Off-road and Tanks and Turrets 2 were much easier to do. All together their have been over 400K downloads and about $30,000 in revenue for about 600 hours of work($50/hour). Currently the series of games is bringing in about $20-$25/day on iOS.

Not bragging or whining, just putting out data for others that might want to try their hand at writing iOS games.

My current project, Puzzlling Cubes, is a puzzle game using Unity. It will launch December 14th on iOS and Android. I will publish information on that launch after I get about a months worth of data.

Links to current games –