#Recipe Scriptusing System.Collections.Ge...

1 messages · Page 1 of 1 (latest)

cunning ivy
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

cunning ivy
#

One message removed from a suspended account.

#

One message removed from a suspended account.

stoic folio
#

it is supposed to be shown when all ingredients are avaible

cunning ivy
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

stoic folio
#

it takes 2 items with an amount fo 1

#

of*/

cunning ivy
#

One message removed from a suspended account.

stoic folio
#

no

#

you are supposed to consume both materials after crafting

cunning ivy
#

One message removed from a suspended account.

#

One message removed from a suspended account.

stoic folio
#

yes

#

basically the problem is that even though there are not enough materials to craft,it is still craftable

cunning ivy
#

One message removed from a suspended account.

#

One message removed from a suspended account.

stoic folio
#

yes

cunning ivy
#

One message removed from a suspended account.

#

One message removed from a suspended account.

stoic folio
cunning ivy
#

One message removed from a suspended account.

cunning ivy
#

One message removed from a suspended account.

#

One message removed from a suspended account.

stoic folio
#
public class Recipe : ScriptableObject
{
    public List<ItemData> materials = new List<ItemData>();
    public ItemData outputitem;
    public bool Craftable(Inventory inventory)
    {
        List<bool> CanCraft = new List<bool>(materials.Count);
        Debug.Log(materials.Count);
        for (int i = 0; i < materials.Count; i++)
        {
            Debug.Log(i);
            if (inventory.items[i] == materials[i])
            {
                CanCraft[i] = true;
                Debug.Log(CanCraft[i]);
            }
        }
        return CanCraft.TrueForAll(x => x);
    }
}

#

i updated thes cript with debug logs

cunning ivy
#

One message removed from a suspended account.

#

One message removed from a suspended account.

stoic folio
#

i did get an error saying the index is out of range

#

i added a -1 to the material.count in the forloop

cunning ivy
#

One message removed from a suspended account.

stoic folio
#

now it works even with only 1 material

#

btw this is before i simplify it

#

it no longer works

cunning ivy
#

One message removed from a suspended account.

stoic folio
# cunning ivy One message removed from a suspended account.
public abstract class Item : ScriptableObject, IEquatable<Item>
{
    public int ID;
    public string Name;
    [TextArea(1,20)]
    public string Description;
    public Sprite Icon;
    public bool IsStackable;


    public bool Equals(Item other)
    {
        return ID == other.ID;
    }
}
[Serializable]
public class ItemData : IEquatable<ItemData>
{
    public Item item;//{ get; private set; }
    public int amount;//{ get; private set; }
    public ItemData(Item item)
    {
        this.item = item;
        AddCount();
    }

    public void AddCount()
    {
        amount++;
    }

    public bool Equals(ItemData other)
    {
        return this == other;
    }

    public void RemoveCount()
    {
        amount--;
    }
}
#

this is the class

#

inventory.items has a list of itemdata

cunning ivy
#

One message removed from a suspended account.

#

One message removed from a suspended account.

stoic folio
#

it works now @cunning ivy

#

i literaly don't have enough words to thank you

#

that problem was making me insane for days

cunning ivy
#

One message removed from a suspended account.

stoic folio
#

@cunning ivy sorry to bother you,but there seems to be 2 new issues

#

i tried changing the recipe to use 2 swords and now when i craft it,it only consumes 1

#

i think it is because of the recipe instance script

#
public class RecipeInstance : MonoBehaviour,IPointerClickHandler
{
    public Recipe item;
    [SerializeField] Image ItemImage;

    public void Init(Recipe recipe)
    {
        item = recipe;
        ItemImage.sprite = recipe.outputitem.item.Icon;
        name = recipe.name;
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        foreach (ItemData item in item.materials)
        {
            Inventory.Instance.RemoveItem(item.item);
        }
        for (int i = 0; i < item.outputitem.amount; i++)
        {
            Inventory.Instance.AddItem(item.outputitem.item);
        }
        Destroy(gameObject);
    }
}
cunning ivy
#

One message removed from a suspended account.

#

One message removed from a suspended account.

stoic folio
# cunning ivy One message removed from a suspended account.
public void RemoveItem(Item item)
    {
        if (itemdata.TryGetValue(item, out ItemData tryid))
        {
            tryid.RemoveCount();
            InventoryUpdated?.Invoke(this, tryid);
            ItemRemoved?.Invoke(this, tryid);
            if (tryid.amount == 0)
            {
                items.Remove(tryid);
                itemdata.Remove(item);
            }
        }
    }

the inventory script doesn't accept itemdata,it only accepts items

cunning ivy
stoic folio
# cunning ivy One message removed from a suspended account.

like this?

public void OnPointerClick(PointerEventData eventData)
    {
        for (int i = 0; i < item.materials.Count; i++)
        {
            Inventory.Instance.RemoveItem(item.materials[i].item);
        }
        for (int i = 0; i < item.outputitem.amount; i++)
        {
            Inventory.Instance.AddItem(item.outputitem.item);
        }
        Destroy(gameObject);
    }
cunning ivy
#

One message removed from a suspended account.

stoic folio
cunning ivy
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

stoic folio
#

ok so for the second issue

#

basically it is a dupe glitch with the equipment system

#

    public void Equip(Weapon weapon)
    {
        if (this.weapon != null)
        {
            UnEquip(this.weapon);
        }
        this.weapon = weapon;
        OnEquipWeapon?.Invoke(this, weapon);
    }

    public void UnEquip(Weapon weapon)
    {
        if (this.weapon != null)
        {
            Weapon unequipingweaponing = this.weapon;
            Inventory.Instance.AddItem(unequipingweaponing);
            weapon = null;
            OnUnequipWeapon?.Invoke(this, weapon);
        }
    }
}
cunning ivy
#

One message removed from a suspended account.

#

One message removed from a suspended account.

stoic folio
cunning ivy
#

One message removed from a suspended account.

#

One message removed from a suspended account.