add few items into ...
 
Notifications
Clear all

add few items into inventory at a time

7 Posts
2 Users
0 Reactions
784 Views
(@megaman)
Posts: 34
Trusted Member
Topic starter
 

Hello.

I would like to add few items into inventory on first login, after registration is succeed.  The question is:  what is best way/elegant method to do that without using For loop?

for (int i = 0i < startItems.Count; ++i)
    {
        // Search the item in the current inventory
        Inventory newItem = inventoryItems.Finditem => item.name.Equals(startItems[i].name) );
        if (newItem != null) {
            Debug.Log(newItem.name + " " + newItem.quantity + " exists");
        } else {
            Debug.Log(startItems[i].name + " doesn't exist then create it now");
            newItem = new Inventory();
            newItem.name = startItems[i].name;
            newItem.quantity = startItems[i].quantity;
            newItem.Update( (bool successstring errorrr) => {
                if (success) {
                    Debug.Log("Update success ");
                } else {
                    Debug.Log("ERROR: " + errorrr);
                }
            });
        }
    }

 

thank you!

 
Posted : 23/06/2015 9:32 am
(@skaredcreations)
Posts: 806
Prominent Member Admin
 

First, download the newly uploaded Combu 2.0.3 (currently available only on this website, will be uploaded to Asset Store sooner) that fixes an issue in the inventory load webservice.

About your topic, if you want to do this on the client side then the only way is as you're doing with a loop, else you could save traffic by moving the logic on the server side: with this latest version I added a sample code in the function wsCreate of users.php to show how to easily add a starting equipment upon user registration directly on the server, this will save you traffic and logic on your client (eventually remember to make a backup of this file before upgrading in the future versions to restore your own piece of code for starting equipment).

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 23/06/2015 1:19 pm
(@megaman)
Posts: 34
Trusted Member
Topic starter
 

Works perfect! Thanks a lot.

 
Posted : 23/06/2015 9:07 pm
(@megaman)
Posts: 34
Trusted Member
Topic starter
 

In users.php i have "STARTITEMS" code to create start items for every new account created: 

$startItems = array(
array( "name" => "item1", "quantity" => 1 ),
array( "name" => "item2", "quantity" => 1 )
);
foreach ($startItems as $itemData) {
$newItem = new CB_Inventory();
$newItem->IdAccount = $user->Id;
$newItem->Name = $itemData["name"];
$newItem->Quantity = $itemData["quantity"];
$newItem->Save();
}

 

Everything fine if i create user in regular way with login and password, but when i login(create user) with  Facebook login the "STARTITEMS" code doesnt trigger. How can i fix that? 

 

Thanks a lot and have a great day.

 
Posted : 27/06/2015 9:24 am
(@skaredcreations)
Posts: 806
Prominent Member Admin
 

Yes, it's only in the registration we service, you have to change also the login platform web service too or wait for me to make the changes next week.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 27/06/2015 3:29 pm
(@skaredcreations)
Posts: 806
Prominent Member Admin
 

Download version 2.0.4, you will find the demo code commented in the functions wsCreate and wsLoginPlatform to add starting equipment to new users. This update has been submitted now to Asset Store too and should be available there within the current week.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 29/06/2015 12:08 pm
(@megaman)
Posts: 34
Trusted Member
Topic starter
 

Skared Creations said
Download version 2.0.4, you will find the demo code commented in the functions wsCreate and wsLoginPlatform to add starting equipment to new users. This update has been submitted now to Asset Store too and should be available there within the current week.

Thanks a lot, your are the man! 

 
Posted : 30/06/2015 3:00 pm
Share: