Hey so I’ve been using smart strings in the localization package and they are great but I’ve come to an issue which seems like it should have a good solution for but maybe I’m not seeing it.
The essence of what I’m doing is I have cost for something I want the player to buy. In the UI I want to show the owned amount over the cost, like so 2/3. That by itself is fine, just doing {owned}/{req} works but its the next step that’s bothersome. If the owned amount is less than the requirement I want the owned amount to be red but otherwise just have the normal formatting. I tried
{owned:cond:<{req}?<color=”red”>{owned}/{req}| {owned}/{req}}
but it always results in the later case no matter what I set it to. In the past I solved this by making another bool variable to do the below but it’s very hacky as I have to adjust that variable in code each time the other values change which is not ideal.
{hasEnough:<color=”red”>{owned}/{req}| {owned}/{req}}
Would love if there was some nicer way to get around this.
I think the problem is that you are trying to compare a placeholder value. We don’t support extracting values like that, req needs to be literal. It would be nice but the system is not built for those types of comparisons. I’ll make a note for us to see if we could add some support for this in the future.
For now, you need a literal, e.g
{owned:cond:<10?<color=”red”>{owned}/{req}| {owned}/{req}}
Alternatively, you could try creating a custom formatter Creating a custom formatter | Localization | 1.5.3
Thanks for the quick response. With the custom formatters is it possible to supply two variables into it? Otherwise just have to use my hack for now. Can’t use literals as the requirements are the req is data driven.
You should have access although i depends where req is coming from. What type of variable is it, do you pass it in with the arguments or is is a global/local variable?
One quick hack would be to do a simple find and replace on the string before you format it although I’m sure we can work something better out 