Download

How to Communicate Between Variables?

Hi I’m trying to make a RPG like system where you can change character stats by equipping weapons and armor. But I really don’t know how to do this:

Say Character has 20 HP. He then equips a Iron Vest that has +5 HP on it. How can I tell the Character to change it’s HP to 25 once the Iron Vest is equipped? Thank you. I’ve tried “Cast To as” and also have tried and failed to use Arrays to get this simple task done. Any tips? thanks!

the question should be rephrased as “how do I trigger events when equip/unequip items?” since variable can’t communicate, you communicate by trigger event and send variables or references.

once you follow this path, it would be easier to update character stats.

thanks, so maybe I worded it wrong, but how do I do it? =p

I tried a whole bunch of Cast To and Arrays stuff but couldn’t figure it out

Assuming your Iron Vest is a Blueprint then you’ll need a trigger for your Iron Vest. You can add a sphere/box component for this and when you overlap this trigger, cast the overlapping actor to your pawn and set your health to health + 5.

But if you plan to have multiple vests (like Gold Vest, Silver Vest etc) then the best way is to create a master vest Blueprint and create all your vests based on this master class. In your master vest class create an Event Dispatcher (eg: EventDisp_VestPickedUp) and in your child classes bind this event in Begin Play and apply your health accordingly to your vest. Like Gold Vest gives +15 health, Silver gives +10 health etc.

thanks ryanjon2040 so it’s event dispatchers I need to figure out. Now that I know what tree to bark up I feel like I’m half way there

Happy to help :).

i will do something like this:

in your item blueprint create a variable “Armor=XX”
Then:

Character -> Get/Attach (your get function) -> Itemequip
CharacterArmor (var in character) + Itemequip -> Get Armor()
Drop
CharacterArmor - Drop/Detach -> Get Armor()

More easy and not need event dispachers or interfaces.