Question by
TimChadz · Mar 24, 2017 at 11:31 AM ·
c#kongregate
Kongregate and Kreds
I've searched high and low, but found little information on how to interact with Kongregate's 'kred' system using unity and C#. Surely someone else has had luck in this?
There are plenty of examples of establishing a connection to their API.
This is broadly speaking two tasks:
1) Requesting the purchase of an item. I suppose it would start something like this (question marks for parts I don't know):
public void PurchaseItems(string[] itemIDs)
{
// Passing item IDs as array of strings
Application.ExternalCall("kongregate.mtx.purchaseItems", itemIDs);
// Add a listener for the on purchase kongregate event
//??? what's the event name? (e.g. for login it is simply 'login')
//??? the param sent to the callback function should just be a bool (success state of the purchase) - how should this be specified?
Application.ExternalEval(@"
kongregate.services.addEventListener('????', function(){
var unityObject = kongregateUnitySupport.getUnityObject();
var services = kongregate.services;
var params=[????].join('|');
unityObject.SendMessage('KongregateAPI', 'OnPurchaseResult', params);
});"
);
}
void OnPurchaseResult(bool result)
{
if (true)
{
// Game specific stuff due to successful purchase
}
}
2) Obtaining a list of purchased items I suppose it would start something like this (question marks for parts I don't know):
public void QueryItemsOwned()
{
// Calling with null to specify current user
Application.ExternalCall("kongregate.mtx.requestUserItemList", null);
// Add a listener for the on user items kongregate event
//??? what's the event name? (e.g. for login it is simply 'login')
//??? the params sent to the callback function should just be a bool (success) and an array of data on each item - how should this be specified?
Application.ExternalEval(@"
kongregate.services.addEventListener('????', function(){
var unityObject = kongregateUnitySupport.getUnityObject();
var services = kongregate.services;
var params=[????].join('|');
unityObject.SendMessage('KongregateAPI', 'OnUserItems', params);
});"
);
}
void OnUserItems(????)
{
// Should in theory recieve a bool for success and an array of item objects?
// each object in the array should have:
// int id - unique id of the item
// string identifier - the item identifier
// string name - the player facing name of the item
// string description - the player facing description of the item
// int price - the price of the item in kreds
// array tags - an array of strings containing the tags for the item
// string image_url - the player facing image for the item
if (success)
{
// Extract the item list
for (int i = 0; i < itemData.Length; i++)
{
// ??? how to extract the data from each item?
//int id = ;
//string identifier = ;
//string name = ;
//string description = ;
//int price = ;
//array tags = ;
//string image_url = ;
}
}
}
}
Any ideas?
Comment