Forum PayVault Deletes all vault items at once :3 ?

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

Deletes all vault items at once :3 ?

Postby TD » March 16th, 2016, 5:31 pm

Trying to make it possible to delete all users items at once without have x100 consume lines, i want 1 consume line to consume all items
I tried this


Code: Select all
vault.Refresh(delegate ()
                    {


                        foreach (var items in allitems)
                        {
                            Int32 now = vault.Count(items);
                            if (vault.Has(items))
                            {
                                int repeat = now;
                                for (int i = 0; i < repeat; i++)
                                {
                                    VaultItem item = vault.First(items);

                                    Console.WriteLine("The Player has: " + items);
                                    vault.Consume(new VaultItem[] { item }, delegate ()
                                            {

                                                //Console.WriteLine("The Player has: " + items);
                                            });

                                }

                            }
                        }


It works but once it finds, the item in the items array that the vualt does not contain its Gives Error
(Picture Below)
Can this be fixed ?


Link for pic if it does not load below : http://prnt.sc/ag19fg
Attachments
Screenshot_7.png
The Error
Screenshot_7.png (15.32 KiB) Viewed 4049 times
TD
 
Posts: 11
Joined: February 3rd, 2016, 3:56 pm

Re: Deletes all vault items at once :3 ?

Postby Henrik » March 21st, 2016, 4:05 am

Uh, there's a bunch of things that are weird here.

Why would that method try to delete items that don't exist in the first place? Do you have someone else accessing that player's vault in the first place?

Why are you looping over the variable allitems, when you don't update that inside the Refresh callback? That means you are iterating over some other collection of items and not the player's current items.

Why are you using the First property and a count of the items and a for loop? Why not just iterate over all the items with a foreach statement?

Every method has an optional error handler. You should use that to decide in code what happens when you call Consume on an item that does not exist.

And fifth, that way will make one webservice call for each item you want to consume, which uses a lot of resources. Consume takes as an argument an array of items and consumes them all, so why not call it once on the entire array of items and be done with it? Like this:

Code: Select all
vault.Refresh(delegate() {
    Console.WriteLine("The player has: " + vault.Items.Length + " items.");
    vault.Consume(vault.Items);
});
Henrik
.IO
 
Posts: 1822
Joined: January 4th, 2010, 1:53 pm

Re: Deletes all vault items at once :3 ?

Postby SharkChase » March 21st, 2016, 1:26 pm

Thanks!
SharkChase
 
Posts: 15
Joined: March 18th, 2016, 1:02 am


Return to PayVault



cron