#From what I can see you have an item

1 messages · Page 1 of 1 (latest)

neon sedge
#

humm

#

Sorry i've learned now the topic stuff here in discord eheh

#

So, if i want to pass the information from the dungeon to main menu

#

what is the best practice?

#

atm i have an object that has DontDestroy Function, and in it i have all character created.
In each character it has an Inventory storing the Scriptable Object for each item the character has in account

#

is there any way to pass for example a Leather Helmet and the correspondent Stats for example Def +4 and Hp +95

#

@south gorge

#

In order to use something that is not a scriptable objects (for example use Monobehaviour) i will need a game object just to attach the script right?

south gorge
#

Yes, which I presume your character already has.
Remember all your characters are sharing the inventory as you have defined it, they dont each have their own

neon sedge
#

yes they have

#

that is already working previously

south gorge
#

Then they are sharing Items

neon sedge
#

Nop they are not, that what is making me confused about it

#

Using the scriptable objects as well

#

1 character can have 10 leathers and other can have 80 without a problem

#

it does not overload like the stats

#

i got messed up about it

south gorge
#

That is not the point

#

each Item is a scriptableobject so a physical file'
if I say char1.item = Item
and char2.item = Item
they are sharing the same object
you need something like
char1.item = Item.Copy;
char2.item = Item.Copy;
to make them distinct

#

then you can set the stats on char1.item and char2.item and they will be different

neon sedge
#

this:

#

    public void CreateDuplicate(Item item){
        id = item.id;
        itemName = item.itemName;
        npcValue = item.npcValue;
        rarity = item.rarity;
        desc = item.desc;
        value = item.value;
        icon = item.icon;
        qnt = 0;
        maxStack = item.maxStack;
        itemType = item.itemType;
        isUsable = item.isUsable;
        isEquipable = item.isEquipable;
        itemPrefab = item.itemPrefab;
        itemPrefabUI = item.itemPrefabUI;
        equipStats = item.equipStats;
        maxEquipStats = item.maxEquipStats;
        durability = item.durability;
    }

south gorge
#

yes, exactly

#

I wold normally do
pubic Item CreateDuplicate() {...}
then call that on the original Item

neon sedge
#

humm i might do it with the Stats

neon sedge
#
    public void GenerateEquipStats()
    {
        equipStats.Clear();
        Debug.Log("GenerateEquipStats (" + maxEquipStats + ")");
        for (int i = 0; i < maxEquipStats; i++)
        {
            EquipmentStat myStat = ScriptableObject.CreateInstance<EquipmentStat>();//item;new EquipmentStat();
            EquipmentStat stat = ScriptableObject.CreateInstance<EquipmentStat>();
            stat.CreateDuplicate(myStat);
            stat.equipment = this;
            stat.RandomizeStatType();
            stat.RandomizeValue();
            equipStats.Add(stat);

            Debug.Log(stat.toString() + " Added to list");
        }
    }
#

Im i doing the CreateDuplicate correct?

#

    public void CreateDuplicate(EquipmentStat stat)
    {
        equipment = stat.equipment;
        statType = stat.statType;
        isPerc = stat.isPerc;
        valueNum= stat.valueNum;
        valuePerc= stat.valuePerc;
        min = stat.min;
        max = stat.max;
    }
south gorge
#

No

#

when you do CreateInstance you are creatng a new instance so no need to duplicate

#

if you have duplicate on Item that is enough

#

your problem is with the equipStats List, not EquipmentStat

#

good point. on duplicate of Item

equipStats = item.equipStats;

should be

equipStats = new List<EquipmentStat>(); 

otherwise you are sharing the list again

#

you need to understand the difference between value types and reference types in C#

neon sedge
#

damn i haven't done that previously

#

ill try now

#

Still same problem

south gorge
#

Did you change the duplicate method or just the List definition?

neon sedge
#

where should i change equipStats = item.equipStats;?

south gorge
#

in the CreateDuplicate method of Item

neon sedge
#

oh it was there already

south gorge
#

change it what I showed or remove it completely. equipStats needs to be a new List not a reference to the old one

#

this
equipStats = item.equipStats;
is NOT making a copy, it just creates a reference to the original

neon sedge
#

ok ill remove it

#

it doesn't work whitout that

south gorge
#

what doesn't work?

neon sedge
#

it loses the conection

#

because everytime i open the inventory i use the createduplicate code

#

so i need to have acces to that line i've commented

#

not even one

south gorge
#

you shouldn't be using CreateDuplicate everytime you open the Inventory
you should only use it when a character gets an inventry item

neon sedge
#

ohhh

south gorge
#

sit down with a piece of paper and a pen and flow chart how this would work irl

neon sedge
#

I put it to work, but i have an issue, if i kill 2 mobs at the same time and they drop an equipment the stats are going to be the same for both

#

i might need to generate a ghost object