Forum PayVault Counting more then one item? possible....?

Discussion and help relating to the PlayerIO payment solution, PayVault.

Counting more then one item? possible....?

Postby oonka » October 23rd, 2015, 1:17 am

Hey today i wanted to try to make my life a bit more easy i made a item array and that works but I'm trying to count more then one item
So i tryied this
But it won't work and i get no errors
Code: Select all
var headItems = ["Cue", "Tokens"];
inv.head_txt.text = TheClient.payVault.count(headItems).toString();
oonka
 
Posts: 22
Joined: October 10th, 2015, 9:19 pm

Re: Counting more then one item? possible....?

Postby Guillaume » October 23rd, 2015, 9:16 pm

What do you want to achieve precisely with this code ?
Guillaume
 
Posts: 277
Joined: March 28th, 2014, 1:59 am
Location: France

Re: Counting more then one item? possible....?

Postby oonka » October 23rd, 2015, 9:18 pm

I'm trying to count items of each item in my array

Example: i have 12 Cue's and 13 Tokens i want it to Count the items i have in my PayVault but only count the Items Array
oonka
 
Posts: 22
Joined: October 10th, 2015, 9:19 pm

Re: Counting more then one item? possible....?

Postby Guillaume » October 23rd, 2015, 9:48 pm

Yes, but from what i see of your code, i don't know what you are expecting as return value.

It would be easier to write your own method/class method in order to do that.

Something like:

Code: Select all
public static string ItemsCountCanonical(Client client, string[] itemsId)
{
    string canonicalResult = string.Empty;

    for (int i = 0 ; i < items.Length ; i++)
    {
         int nb = client.payVault.Count(items[i]);
         canonicalResult += items[i] + ": " + nb.ToString();
         if (i + 1 < items.Length)
            canonicalResult += ", ";
    }
    return canonicalResult;
}


However, if your goal was to create a super items counter, and return all the matched value, just do this:

Code: Select all
public static int ItemsGroupCount(Client client, string[] itemsId)
{
    int nb = 0;

    for (int i = 0 ; i < items.Length ; i++)
    {
         nb += client.payVault.Count(items[i]);
    }
    return nb;
}


Thats all.
Last edited by Guillaume on October 23rd, 2015, 9:50 pm, edited 1 time in total.
Guillaume
 
Posts: 277
Joined: March 28th, 2014, 1:59 am
Location: France

Re: Counting more then one item? possible....?

Postby oonka » October 23rd, 2015, 9:50 pm

Thanks once my Flash CC stops Force closing my Game ill test it :D
oonka
 
Posts: 22
Joined: October 10th, 2015, 9:19 pm

Re: Counting more then one item? possible....?

Postby oonka » October 23rd, 2015, 9:59 pm

Guillaume wrote:Yes, but from what i see of your code, i don't know what you are expecting as return value.

It would be easier to write your own method/class method in order to do that.

Something like:

Code: Select all
public static string ItemsCountCanonical(Client client, string[] itemsId)
{
    string canonicalResult = string.Empty;

    for (int i = 0 ; i < items.Length ; i++)
    {
         int nb = client.payVault.Count(items[i]);
         canonicalResult += items[i] + ": " + nb.ToString();
         if (i + 1 < items.Length)
            canonicalResult += ", ";
    }
    return canonicalResult;
}


However, if your goal was to create a super items counter, and return all the matched value, just do this:

Code: Select all
public static int ItemsGroupCount(Client client, string[] itemsId)
{
    int nb = 0;

    for (int i = 0 ; i < items.Length ; i++)
    {
         nb += client.payVault.Count(items[i]);
    }
    return nb;
}


Thats all.



@Guillaume, Thanks its exactly what I wanted! :D
oonka
 
Posts: 22
Joined: October 10th, 2015, 9:19 pm


Return to PayVault



cron