Unity With C# script : Class Data Type Passing Value From Class With Data Twice Weird -
i got simple question , weird passing value data type class variable.
the code below :
void additem(int id) { (int = 0; < database.items.count; i++) { if(database.items[i].itemid == id) { itemxs = new item (database.items [i].itemname, database.items [i].itemid, database.items [i].itemdesc, database.items [i].harvest, database.items [i].itemtime, database.items [i].stdprice, database.items [i].hightprice, database.items [i].itemstock, database.items [i].lvlunlock, database.items [i].rawtree, database.items [i].itemtype, database.items [i].itemprod, database.items [i].itemicon); debug.log ("item icon 1 : " + database.items[i].itemicon); // appear "corps/lemon" debug.log ("item icon 2 : " + itemxs.itemicon); // appear "corps/lemon/lemon" **even though passing value code itemxs = new item (database.items [i].itemname,...etc)** wierd checkinventoryexist(itemxs); break; } } }
itemicon source base name : basename + itemname; database.items[i].itemicon contain "corps/lemon" problem debug.log database.items[i].itemicon still same string "corps/lemon", when put "itemxs = new item (database.items [i].itemname,....etc" , debug.log itemxs.itemicon contain "corps/lemon/lemon"
what going on ?
thanks
dennis
below class :
item.cs
using unityengine; using system.collections; // make class item public class item { public string itemname; public int itemid; public string itemdesc; public string itemicon; public gameobject itemmodel; public int itemtime; public int hightprice; public int stdprice; public int itemstock; public int harvest; public rawtree rawtree; public itemtype itemtype; public itemprod itemprod; public int lvlunlock; private string basename; // use initialization void start () { } // update called once per frame void update () { } void awake () { } public enum itemtype { raw, admirable, valuable } public enum rawtree { bigtree, smalltree, field, none } public enum itemprod { animalbarm, mining, corps, dairy, juicejammaker, merchant, kitchen, bakery, crafthouse } public item (string name, int id, string desc, int harvestx, int time, int stdpricex, int hightpricex, int stock, int lvlunlockx, rawtree rawtree, itemtype type, itemprod prod, string folder) { itemname = name; itemid = id; itemdesc = desc; harvest = harvestx; itemtime = time; stdprice = stdpricex; hightprice = hightpricex; itemstock = stock; lvlunlock = lvlunlockx; rawtree = rawtree; itemtype = type; itemprod = prod; this.basename = folder + "/"; itemicon = this.basename + itemname; } public item() { } }
then itemdatabase.cs
using unityengine; using system.collections; using system.collections.generic; public class itemdatabase : monobehaviour { public list<item> items = new list<item>(); // use initialization void start () { // add data item list class item // ------------------------------- item corps (raw - big tree) ------------------------------- // items.add (new item ("lemon", 1, "honey lemon", 9, 1020, 75, 158, 0, 1, item.rawtree.bigtree, item.itemtype.raw, item.itemprod.corps, "corps")); } // update called once per frame void update () { } }
when put code :
itemxs = new item (database.items [i].itemname, // contain "lemon" database.items [i].itemid, database.items [i].itemdesc, database.items [i].harvest, database.items [i].itemtime, database.items [i].stdprice, database.items [i].hightprice, database.items [i].itemstock, database.items [i].lvlunlock, database.items [i].rawtree, database.items [i].itemtype, database.items [i].itemprod, database.items [i].itemicon);
itemname contain : "lemon";
itemicon contain: "corps/" + itemname; can check in itemdatabase.cs file , constructor @ item.cs.
so result itemicon must : "corps/lemon" but
why itemxs.itemicon got double itemname ? example : "corps/lemon/lemon".
in item
constructor doing it:
this.basename = folder + "/"; itemicon = this.basename + itemname;
where folder == corps
, this.basename == "corps/lemon/"
, itemname == "lemon"
have should get.
Comments
Post a Comment