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…

241199-untitled2.png

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).

If you have an int variable named “Dat_[CharName]_Str” then this is the name for your allocated variable, just like in C++ with the following statement:

public int Dat_[CharName]_Str;

Changing this variablename (at runtime) is not a good idea and appears to be unnecessary to me.

And I don’t really understand what you want to do or why you want to do it this way. Don’t you have a blueprint actor for every of your characters? If you have them, why don’t you just set the specific variable of that character named “MyStrength” (or something)? “MyStrength” of Elizar’s blueprint will have a different value then Peppar’s blueprint. You only have to cast in which blueprint you are to verify that you are changing Elizar and not Peppar. This is also true if you don’t have blueprints for your characters. You could also make a struct and throw all the information for the character in it and use the struct as a variable which you name “Elizar_Stat” or “Peppar_Stat” or alike so they are stored separately.

Anyway: You shouldn’t use that many branches when you are checking against the same type of information. You can use the “switch” statement and check the stuff. Multiple branches but better and smaller:

Thanks for the help, I’m still missing a lot of knowledge when it comes to Blueprints and didn’t know about the Switch function (nifty!). That’s not exactly what I’m trying to do tho. I’m trying to use a variable as the actual variable name, which I guess I’m explaining wrong…

Put it this way, My variables are a public struct per character that holds their status, and then I have a string variable that would determine which character would be present on the battle field.

var Struct ElizaStats
var Struct PepparStats
var String CurrentCharacter

So my question is, how could I use the “CurrentCharacter” string to call the “ElizaStats” Struct Direction, as in take the string and add a suffix “Stats” to automatically pull the struct without needed a cast from a blueprint without needing to spawn Peppar or create a game-mode call to it.

I’m trying to do it this way because I’m building an RPG but it has some idle-game style mechanics that run along-side gameplay that need other character stats to be calculated in real-time, so I’m trying to avoid duplicating code or spawning/calling extra actors/blueprints when I could centralize these calculations. Currently I have a Game Instance that has a set of functions and variables which would basically perform these actions and update stats whenever required through casts from actor/gamemode blueprints (the actor that would spawn in sets the current character, gamemode then detects that and sends out what the game instance needs to calculate based on a timescale). I’m just trying to simplify it. (and regardless, I still feel it could be a useful thing to know)

Put it this way, My variables are a public struct per character that holds their status, and then I have a string variable that would determine which character would be present on the battle field.
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.

how could I use the “CurrentCharacter” string to call the “ElizaStats” Struct Direction, as in take the string and add a suffix “Stats” to automatically pull the struct without needed a cast from a blueprint without needing to spawn Peppar or create a game-mode call to it.
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.