#From what I can see you have an item
1 messages · Page 1 of 1 (latest)
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?
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
Then they are sharing Items
Nop they are not, that what is making me confused about it
like the game is online in itch.io
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
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
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;
}
yes, exactly
I wold normally do
pubic Item CreateDuplicate() {...}
then call that on the original Item
humm i might do it with the Stats
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;
}
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#
Did you change the duplicate method or just the List definition?
.
where should i change equipStats = item.equipStats;?
in the CreateDuplicate method of Item
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
what doesn't work?
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
you shouldn't be using CreateDuplicate everytime you open the Inventory
you should only use it when a character gets an inventry item
ohhh
sit down with a piece of paper and a pen and flow chart how this would work irl