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 = 0; i < startItems.Count; ++i)
{
// Search the item in the current inventory
Inventory newItem = inventoryItems.Find( item => 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 success, string errorrr) => {
if (success) {
Debug.Log("Update success ");
} else {
Debug.Log("ERROR: " + errorrr);
}
});
}
}
thank you!
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
Works perfect! Thanks a lot.
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.
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
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
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!