Get a Text Description based on an Integer or Float percentage

What’s the best way to do this…?

I have a series of statistics, such as “STAMINA”. Each is represented by a percentage where 90%+ is “Great”, 80%+ is “OK”, 70+ is “Tiring”… etc. The text description is what the player sees.

What’s the most efficient and clear way of converting the percentage to the text description? My previous experience is with VB; and we’d have used a SELECT CASE for this; but that’s babblespeak here, I know.

I’d rather not nest a long line of branches! (For example~:)

Surely this is a very inelegant way to do what I need here; given there’s two other stats I need to handle like this.

Thanks!

i’d do it this way. its not perfect.

come to think about it, no need for select.

Thanks for replying so quickly. I’m not sure what the Left String function is doing here, so I’m unclear on how to check this is working. I’m also not sure what we’re looking up in the String array (my guess)…

So the question is how is it getting the correct descriptor for the percentage value of “Stamina”?

Cheers,

i was in a hurry, i should not post while i am in a hurry.

here, i made it perfect but you will use 1 extra branch, im starting to question if its more efficient after these changes.


Stamina-2

forgot to tell you, this only works from 0 to 99 stamina if you want 100% you need to add an extra branch. up to you

Thanks. I was a bit put off by it as it’s tricky to comprehend, but your solution does work. Having done some additional searching, I don’t seem to the only one who has struggled when trying to “Switch” on “Integer Range”.

I think, however, I have found a more elegant solution by building a reusable function. (I need to do this on at least two other values)

It’s still using nested branches, which is annoying, (Oh for a SELECT CASE and BETWEEN) but it’s manageable as is.

Thank you so much for taking the trouble to reply and offer a solution.

no problem, i enjoy the challenge. i enhanced it and now it works from 0 to 100 with no issues. previous algo had an issue with percentages less than ex: 2% would be reported as 20% now its fixed. only 1 branch :slight_smile:

@anonymous_user_d774775f1 Have a look at InRange nodes:

image

I did have a little poke about with that; but the fact it would still need branch logic to work in my case makes it a bit of a faff. If there was a “Switch on Bool” of some sorts, maybe… but with 6 ranges to work with, InRange doesn’t seem to be my saviour.

Is there a way to implement it in a neat fashion, do you think? The method I’ve dreamed up above, with the Pure Function is useful (to me) as it’s reusable.

Thanks for your input.

I was looking at this thread before, thinking this pseudoscript would be neat:

But it does not really give you lots of flexibility or granularity :expressionless:


does not really give you lots of flexibility or granularity

BUT! You could make the Map 100 elements long, each int is associated with a descriptor:

image

Then you can control which descriptors kicks precisely at which percent, with the precision of 1 percent. You could quickly make it in a spreadsheet, chuck it into the data table even. Sounds like an overkill but it would be neat-ish in a way.

You could also remap the range of stat values to an index using a curve.
So, you’d have a curve going from STAMINA to a 0 … 1 value, which would let you control the resolution and response, and then you’d have something that picks one of N strings from that 0 … 1 range.

1 Like

Ah, a curve would work! +1

i second curve use. I just discovered them not long ago and have found that they can save tons of nodes and make for easier iteration/experimentation. Anything from adjusting camera spring arm to animations to character rpg stat values. Pretty much anything. I wish I had learned about them sooner.

(just saying this to further motivate any future readers to take a moment to learn how to use curves )

1 Like

This sounds quite inventive - and I’d like to try it. Familiar enough with the concept of mapping a curve to a timeframe or animation - but not to values like this. Do you have a recommendation for where to find a learning resource for this that might cover my needs? What I found in the documentation on curves seems to reflect things like animations.

Unreal Engine - Slow/Speed Character Movement On Slopes (Simplest Method) - YouTube

here’s a lengthy step by step ^ . If you search unreal curves on youtube:


These first two guys are both great for quick beginner intros. Always recommend them.

but it’s simple, just a couple screenshots from my own project probably gets idea across:
Here I am using a curve to change my characters speed based on the ground slope. Speed Curve (blue variable) is reference to the curve. Get Float Value takes a float input (in this case, the angle of ground), and the curve you create makes the corresponding outputs.

You can see up there at the top, I have said that when the input is 10, the output will be 1. In this case that means when the slope is slight, I multiply my speed by 1, so no change.

I am also using curves to change the spring arm length of the camera based on speed. helps give sense of momentum and acceleration.

I also use to update characters status effects like temperature, thirst, hunger, and so on. Basically, any time I want to map a range of values, I use a curve. Because the only other alternative I know if lengthy branch chains. With a curve it’s all in one easy to edit and visually understandable spot.

I think you might find more advanced examples related to animation in the Advanced Locomotion v4 project which is free.

1 Like