Ren'Py Convert a referenced integer into a text string?

apolloladdie

Member
Aug 5, 2017
388
770
Herro' out there.
Quick, potentially stupid question. I am trying to perform a numbered variable to text string conversion in a conversation.

In one file, I have the variables defined (appropriate tabs are marked by >'s and are not actually put into the code)

label create_[hero.fname]_[hero.lname]
>$ hero.fname = "player"
>$ player.days = 13 (and this variable is able to change through the game)
> ......(this is just strings other variables)

Then in the field where the speech text happens, the line is something like:
> Speaker "Hi [hero.fname], it seems to me that you have been here for [player.days] days. It is time to pay rent.

The resulting dialog will end up being:
> Speaker Hi player, it seems to me that you have been here for 13 days. It is time to pay rent.

And I am looking for: (It just looks better for a person to say the written form of a number then the ## form IMO)
> Speaker Hi player, it seems to me that you have been here for thirteen days. It is time to pay rent.


I have tried %[player.days]d and the result says that there has to be a number, and not unicode. Any help would be greatly appreciated.
 

GNVE

Active Member
Jul 20, 2018
724
1,185
Just want to add that this will make translations harder. In German (or Dutch) for instance you will say dreiunddreissig litt: three and thirty while French is an even bigger mess: quatre vingt dix huit which translates to four twenty ten eight or ninety-eight. Not saying you shouldn't just giving a fair warning. :)
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,229
Just want to add that this will make translations harder. In German (or Dutch) for instance you will say dreiunddreissig litt: three and thirty while French is an even bigger mess: quatre vingt dix huit which translates to four twenty ten eight or ninety-eight.
That's the main problem, yes. As shown by your two examples, the real problem is that the structure of the resulting texts will not always follow the same logic. Therefore, any translation will have to include a reworked version of the code used to make the conversion number to words.
It also imply that he'll have to write the code himself, because the two modules named in the Stack Overflow's entry will limits the possibility of translation.
 
  • Like
Reactions: apolloladdie

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,608
2,256
Firstly, nobody is going to care if your game says "you have been here for 13 days" as opposed to "you have been here for thirteen days". You're potentially creating a complicated solution to a problem your players won't care about.

But meanwhile...

If you've got a "reasonable" number of days to cope with, you could just write out the names yourself, which in turn would make translation easier too.

If you only pay the rent weekly or fortnightly... that would make things more practical.

Python:
define day_text = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]

define week_text = ["zero", "seventh", "fourteenth", "twenty first", "twenty eighth", "thirty fifth", "forty second", "forty ninth", "fifty sixth", "sixty third", "seventieth"]

default day = 0
default week = 0

label start:

    "*** START ***"

label repeat_days:

    $ day += 1
    if day <= 10:
        $ dtext = day_text[day]
        if day == 1:
            "You have been here for [dtext] day, blah, blah."
        else:
            "You have been here for [dtext] days, blah, blah."
        jump repeat_days

label repeat_weeks:

    $ week += 1
    if week <= 10:
        $ wtext = week_text[week]
        "It's the [wtext] day since you moved in, blah, blah, blah."
        jump repeat_weeks

    "*** END ***"

    return
There has to be a better way than creating extra variables to pass the list array values into dialogue... but for the moment it's completely eluding my ability to use google.

Regardless, if your game is finite... you could code it yourself. If it's completely open ended, with no end in sight... yeah... just use "13" not "thirteen".

Also... on the topic of translations...
You don't have permission to view the spoiler content. Log in or register now.
 

apolloladdie

Member
Aug 5, 2017
388
770
I understand that most people will not care if it is written as 13 or thirteen. From my point of view though, seeing "thirteen" in a speech panel is something that looks like it would be spoken, vs 13 which seem cold and sterile. As of now, I am leaving it as "13". Thank you everyone who has put in their thoughts.