Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im pretty new to coding im trying to figure out how to change my health value and slider value when i put an item on that has buff value

C#
public void OnAddItem(InventorySlot _slot)//equip
    {
        if (_slot.itemObject == null)
            return;
        switch (_slot.parent.inventory.type)
        {
            case InterfaceType.Inventory:

                break;
            case InterfaceType.Equipment:
                // slider.value = healthManager.playerCurrentHealth;//
                print(message: string.Concat("Placed ", _slot.itemObject, " on ", _slot.parent.inventory.type, ", Allowed Items: ", string.Join(", ", _slot.AllowedItems)));
                
                for (int i = 0; i < _slot.item.buffs.Length; i++)
                {
                    for (int j = 0; j < attributes.Length; j++)
                    {
                        if (attributes[j].type == _slot.item.buffs[i].attribute)//if attribute on item is same as on char
                            attributes[j].value.AddModifier(_slot.item.buffs[i]);//take attr on char take value add modifier
                    }
                }


What I have tried:

im pretty new i tried slide.value = playerHealthManager but i think i need the buff value put in there somewhere
Posted
Updated 17-Nov-20 20:32pm
v3
Comments
BillWoodruff 17-Nov-20 21:20pm    
can't read your mind: what does the value of the slider represent ? what does "health value" mean ? "buff" means null ?

what is happening now that causes an error, or that you believe is an error ?
Member 14993595 17-Nov-20 21:41pm    
there is no error.. the value of the buff is on the item itself i put a min value and max value and when its equipped it picks a value inbetween.. my health represents player health but when the item is equipped it DOES NOT actually change my health.. and the value of the slider is obviously once again for the health value.

1 solution

If you only have the one slider for the one player, great a "global" i.e. static reference to the slider. When the player health is updated, update the slider.
C#
class YYY
public static Slider HealthSlider { get { return this.xxxx; } }
...
...
YYY.HealthSlider.Value = ...

If you have a global "collection", use a static for that too (e.g. the armory).

This is one situation where "globals" are good, and you should understand why ... so you can defend yourself when (most) everyone else will say not to.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900