Notifications
Clear all

CB Inventory

3 Posts
2 Users
0 Likes
1,285 Views
(@maroku)
Posts: 7
Active Member
Topic starter
 

Hi again!

i have a little problem with the CB Inventory.

I want to have more then "name" and "quantity" and i dont like to use customData to store more information at 1 item.
So i tryed to add more to the SQL Database and changing the sourcecode a bit.

In the SQL Database in CB_Inventory i added a new field called "ClassLevel" with the same options from quantity.
In the sourcecode "CBInventory.cs" i added "public int classlevel;" under quantity.

I also added this to the CBInventory.cs :
if(hash.ContainsKey("ClassLevel"))
int.TryParse(hash["ClassLevel"].ToString(), out classlevel);

In the sourcecode "CBManager.cs" i added "form.AddField("ClassLevel", inventoryItem.classlevel.ToString());" under quantity aswell.

and this is the code i use to create a new item (in Javascript (Unity).

var slot : CBInventory[];
function OnInventoryLoaded(inventoryItems : CBInventory[]) {

slot = inventoryItems;
var addSlot = slot.Length + 1;
var myNewItem = new CBInventory();

myNewItem.name = "Item " + addSlot.ToString();
myNewItem.quantity = 1;
myNewItem.classlevel = 1;

CBManager.instance.UpdateInventory(myNewItem);
}

All runs well with adding items to the SQL Database but the field "ClassLevel" is 0 and not 1.

So my question is why is the ClassLevel 0 instead of 1?
Did i forget something to change in the source or SQL Database?

Edit: Ignore the in the text

 
Posted : 09/05/2013 3:06 am
(@maroku)
Posts: 7
Active Member
Topic starter
 

I guess i solved the problem. i edited some things from the php files to get it to work

 
Posted : 09/05/2013 10:49 am
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

Hi,

yes of course if you want to add more fields to the database tables then you need to change both the Unity classes in the client and its related class in the server PHP files.

However it's not needed to add more fields to only have "named" properties for your player's info or inventory items, I find much more elegant to create a class which extends the combu's base classes and it's painless since don't require you to change combu's code.

For instance, you could create your own class MyInventory to wrap CBInventory customData into named properties (if you use JS then you should make getter/setter functions, like getClassLevel() and setClassLevel(int level)):

public class MyInventory : CBInventory {
	public int ClassLevel {
		get {
			return (!customData.ContainsKey("ClassLevel") ? 0 : int.Parse(customData["ClassLevel"].ToString()));
		}
		set {
			customData["ClassLevel"] = value;
		}
	}
}

This way you don't touch any combu source code and are free to use more user-friendly names for your custom data (when you load the inventory, in the callback just cast to the items to MyInventory in the example above).

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 09/05/2013 11:42 am
Share: