An efficient way update current virtual goods list and remove products player already has max quantity of?
L
Lord Nal
started a topic
over 7 years ago
ok so i currently have my store inventory being populated by ListVirtualGoodsRequest, is there any particular methods used to have the products the player already has a max quantity of automatically disable the UI Buttons "intractable" tab for that product?
I have an idea as far as maybe using AccountDetailsRequest to create a list and somehow disable all of the gameobject relative to the same ShortCode but I honestly have no idea how to write it in C#..
thanks in advance,
-CJ
Best Answer
T
Tech Support
said
over 7 years ago
Morning guys,
I've quickly put something together for you:
//Send AccountDetailsRequest with the player that called this Event, and get their VirtualGoods
var vgs = new SparkRequests.AccountDetailsRequest().Send().virtualGoods;
// If the player has Virtual Goods
if(vgs){
//Iterate each Virtual Good
for(var i in vgs){
//If the current ammount is equal to the maxQuantity
if(Spark.getConfig().getVirtualGood(i).getMaxQuantity() == vgs[i]){
//Disable UI here
}
}
}
Create a custom event, put this code in the Cloud Code>Events script, log in with a player in Test Harness and call this event. I've commented what's happening where but you might want to step through the code using the debugger so you can see how it works.
You're on the right track with ListVirtualGoodsRequest and AccountDetailsRequest. On the client side, instead of making 2 calls when you display your store(first being ListVirtualGoodsRequest and second being AccountDetailsRequest), create a new event in Cloud Code that does it for you, and returns if the good(s) should be interactable. Your cloud code should do this: 1. Get ListVirtualGoodsRequest 2. Get AccountDetailsRequest 3. For each good, set a field in the return object that determines if the button is clickable.
Was this in line with what you were asking?
L
Lord Nal
said
over 7 years ago
OMG! yes! you tookthe words right out of my head! lol do you have an example script i could reference Davandra? Im still trying to wrap my head around this cloud coding thing.
Tech Support
said
over 7 years ago
Answer
Morning guys,
I've quickly put something together for you:
//Send AccountDetailsRequest with the player that called this Event, and get their VirtualGoods
var vgs = new SparkRequests.AccountDetailsRequest().Send().virtualGoods;
// If the player has Virtual Goods
if(vgs){
//Iterate each Virtual Good
for(var i in vgs){
//If the current ammount is equal to the maxQuantity
if(Spark.getConfig().getVirtualGood(i).getMaxQuantity() == vgs[i]){
//Disable UI here
}
}
}
Create a custom event, put this code in the Cloud Code>Events script, log in with a player in Test Harness and call this event. I've commented what's happening where but you might want to step through the code using the debugger so you can see how it works.
Regards,
Mantas Danilovas
1 person likes this
L
Lord Nal
said
over 7 years ago
Awesome! thank you Mantas!!
-CJ
D
Davendra Jayasingam
said
over 7 years ago
Yup Mantas nailed it. Here's more of what I was thinking of, in which the cloud code returns all your items, and if they are clickable (interactable).
// request all the available virtual goods
// the response is something like this
// [
// {
// "shortCode": "VG_First",
// "currency1Cost": 1,
// "maxQuantity": 1, << NOTE: only displayed if you set the max quantity
// "description": "This is my first Virtual Good",
// "name": "First Virtual Good"
// },
// {
// "shortCode": "VG_Second",
// "currency1Cost": 0,
// "currency2Cost": 1,
// "description": "This is my second Virtual Good",
// "name": "Second Virtual Good"
// }
// ]
var availableVirtualGoods = Spark.sendRequest(new SparkRequests.ListVirtualGoodsRequest()).virtualGoods;
// get all owned virtual goods
// the response is something like this
// {
// "VG_First": 1,
// "VG_Second": 5
// }
var ownedVirtualGoods = Spark.getPlayer().getVirtualGoods();
// loop through each available virtual good to set it's interactability
for (i = 0; i < availableVirtualGoods.length; i++) {
var virtualGood = availableVirtualGoods[i];
// if there is a maxQuantity field, and the player has already purchased it, and the player has the max quantity, set the iteractability to false
if (virtualGood.maxQuantity !== null && ownedVirtualGoods[virtualGood.shortCode] == virtualGood.maxQuantity) {
virtualGood.interactable = false;
} else {
virtualGood.interactable = true;
}
}
Spark.setScriptData("result", availableVirtualGoods);
// you response will be something like this
// {
// "@class": ".LogEventResponse",
// "scriptData": {
// "result": [
// {
// "shortCode": "VG_First",
// "currency1Cost": 1,
// "maxQuantity": 1,
// "description": "This is my first virtual good",
// "name": "First Virtual Good",
// "interactable": false
// },
// {
// "shortCode": "VG_Second",
// "currency1Cost": 0,
// "currency2Cost": 1,
// "description": "This is my second Virtual Good",
// "name": "Second Virtual Good",
// "interactable": true
// }
// ]
// }
// }
L
Lord Nal
said
over 7 years ago
Sorry for all of the questions, but whats a good way to disable the UI Button from the cloud? took a moment to try and figure it out myself but i couldn't find documentations on on it..
-CJ
H
Hong Leong
said
over 7 years ago
Actually there is no good way or bad way, it is only how to code it to get the result.
L
Lord Nal
said
over 7 years ago
ooo sorry Davendra i didn't see your example until after i sent that last reply! lol it makes since now. going to apply your method now! :)
-CJ
L
Lord Nal
said
over 7 years ago
ok last question and i think I will officially have this problem solved... Im trying to apply Davendra's method but cant seem to write the string correctly in C#. can you tell me what im doing wrong with the second line:
new LogEventRequest_OWNED().Send((LogEventResponse response) => {
if(!response.HasErrors){
List<object> entryList = response.ScriptData.GetObjectList("result") as List<object>;
for(int i = 0;i < entryList.Count; i++) {
Dictionary<string, object> entry = entryList[i] as Dictionary<string, object>;
virtualGoodEntry.GetComponent<SHOPVGButton>().TitleString = Convert.ToString(entry["name"]);
virtualGoodEntry.GetComponent<SHOPVGButton>().CostString = Convert.ToString(entry["currency1Cost"]);
}
}
});
L
Lord Nal
said
over 7 years ago
that worked perfectly Hong!! thank you all so much!! I've been struggling with this shop section for almost 2 weeks! I'm finally worthy of a good nights sleep again! haha
Lord Nal
ok so i currently have my store inventory being populated by ListVirtualGoodsRequest, is there any particular methods used to have the products the player already has a max quantity of automatically disable the UI Buttons "intractable" tab for that product?
I have an idea as far as maybe using AccountDetailsRequest to create a list and somehow disable all of the gameobject relative to the same ShortCode but I honestly have no idea how to write it in C#..
thanks in advance,
-CJ
Morning guys,
I've quickly put something together for you:
Create a custom event, put this code in the Cloud Code>Events script, log in with a player in Test Harness and call this event. I've commented what's happening where but you might want to step through the code using the debugger so you can see how it works.
Regards,
Mantas Danilovas
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstDavendra Jayasingam
1. Get ListVirtualGoodsRequest
2. Get AccountDetailsRequest
3. For each good, set a field in the return object that determines if the button is clickable.
Was this in line with what you were asking?
Lord Nal
OMG! yes! you tookthe words right out of my head! lol do you have an example script i could reference Davandra? Im still trying to wrap my head around this cloud coding thing.
Tech Support
Morning guys,
I've quickly put something together for you:
Create a custom event, put this code in the Cloud Code>Events script, log in with a player in Test Harness and call this event. I've commented what's happening where but you might want to step through the code using the debugger so you can see how it works.
Regards,
Mantas Danilovas
1 person likes this
Lord Nal
Awesome! thank you Mantas!!
-CJ
Davendra Jayasingam
Lord Nal
Sorry for all of the questions, but whats a good way to disable the UI Button from the cloud? took a moment to try and figure it out myself but i couldn't find documentations on on it..
-CJ
Hong Leong
Actually there is no good way or bad way, it is only how to code it to get the result.
Lord Nal
ooo sorry Davendra i didn't see your example until after i sent that last reply! lol it makes since now. going to apply your method now! :)
-CJ
Lord Nal
ok last question and i think I will officially have this problem solved... Im trying to apply Davendra's method but cant seem to write the string correctly in C#. can you tell me what im doing wrong with the second line:
new LogEventRequest_OWNED().Send((response) => {
foreach (var entry in response.ScriptData)
{
virtualGoodEntry.GetComponent<SHOPVGButton>().TitleString = entry.Name.ToString();
virtualGoodEntry.GetComponent<SHOPVGButton>().CostString = entry.Currency1Cost.ToString();
}
});
Hong Leong
Hi, this is your solution about your question:
Lord Nal
that worked perfectly Hong!! thank you all so much!! I've been struggling with this shop section for almost 2 weeks! I'm finally worthy of a good nights sleep again! haha
-CJ
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics