Use String to find Defined Variable (And use in cast)
Is there a way to use a String to find a variable? More specifically I want to append a string to grab a value from pre-defined variables and structs. So for example use... and append for my prefix/suffix and then use that output as the variable name, and input that into my function that calculates current stats when entering a stage or changing equipment. I currently use branches for "always active" character stats... then in the function I'd find, let's say "Strength" would be an int "Dat_[CharName]_Str". I would like to just replace [CharName] with a string pulled from the Actor/Pawn/Function but I'm struggling to find how in Blueprints (and I can't find any answers anywhere, tho I'm sure it's possible).
asked May 16 '18 at 07:13 AM in Blueprint Scripting
So I assume that every character has the same set of stats (Health, Strength, XP, etc). This is were I would do things differently. Strings may contain text and therefor information but you most likely need a reference to your character who is present on the battlefield. I would use a variable or an array (for multiple references) which is a reference to the character which entered the battlefield and his/her struct. So you can directly communicate with this specific character and it's values. If Peppar enters the battlefield then you can store or add "PepparStats". No need for a string which you then need to traverse so you know what the information inside of the string actually mean.
If you really want to do it with strings, then I would use multiple append- and split-statements so I can then use a switch-statement to determine what should happen, like setting stuff in your structs. So you don't need a cast or spawn something. As far as I know you can not use a string to tell the engine "give me the variable/array/dictionary with this name!". With actors or references you can get the display, object or pathname but a struct does not have something like that, so you can not compare name-information to call them this way I guess. Using a reference to a actor- or a scene-component would have some kind of name and you can store the struct inside it, so maybe you can create a component of your own and name it the way you need it. With a name you can compare your string information and therefor decide what should happen to whom.
answered May 16 '18 at 12:26 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here