Ren'Py Need help

rackam50

Member
Mar 7, 2018
245
175
Bonjour. Je développe actuellement un software mais je bloque sur la sur la partie récupération du menu.
Voilà comment je récupère le texte actuellement

Hello. I am developing a software but I am stuck on collecting the item menu.
That is how I currently get the text

Code:
init python:
    import inspect
    import pygame.scrap
    import socket
    host="127.0.0.1"
    port=8585
    SocketClient= socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    SocketClient.connect((host, port))

    def send_to_socket(msg):
        SocketClient.sendall(msg.encode("utf8"))

    def text_msg(event, **kwargs):
        if event == "begin":
            d = get_filename_line()
            tl = "%s|separateur|%s" % ((d))
            e = inspect.currentframe().f_back.f_locals
            t="Text"
            line=t+'|separateur|'+tl+'|separateur|'+e.get("what")
            send_to_socket(line)

    def get_filename_line():
        n = renpy.game.script.namemap.get(renpy.game.context().current, None)
        line=""
        if n is None:
            return "unknown", 0
        else:
            return n.filename, n.linenumber
        return


    config.all_character_callbacks.append(text_msg)
J'ai besoin de la même chose pour les choix
j'ai besoin de récupérer le nom du fichier et la ligne de chaque choix.
Si quelqu'un c'est comment faire ça m'aiderait grandement.

I need the same thing for the choices
I need to get the file name and the line of each choice.
If someone is how to do this it would help me greatly.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,188
That is how I currently get the text
I'll not even talk about the intent behind this, but... What the fucking fuck is this fucking mess ?

Python:
init python:
    import socket
    host="127.0.0.1"
    port=8585
    SocketClient= socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    SocketClient.connect((host, port))

    def send_to_socket(msg):
        SocketClient.sendall(msg.encode("utf8"))

    def smtf( text ):
            send_to_socket( "Text\t{}:{}\t{}".format( renpy.get_filename_line()[0], renpy.get_filename_line()[1], text ) )
            return text

    config.say_menu_text_filter = smtf
And it's done, you absolutely don't need more.
No need to twist a callback not intended for this use, nor to redefine one of the API function without even changing a single thing in it.

And now, let's talk about the intent... Because I totally fail to see the interest, at least as your code was initially designed. You get the text, and it's all you can do, you can't change it or whatever... Therefore you're just mimicking Ren'Py's "already seen" behavior, but on an external server.
 

rackam50

Member
Mar 7, 2018
245
175
I haven't implemented your code yet. what you see was the old code I haven't looked at what your code is sending back to me yet I'll analyze it tomorrow anyway thanks for your help and for the information I suck in python that's why I ask help
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,188
I haven't implemented your code yet. [...] yet I'll analyze it tomorrow [...]
Is it so difficult to look at the documentation to read the two sentences, for less than 40 words, related to the config.say_menu_text_filter callback ?
One minute, it's the time it would take, and it would tell you more than a long analyze of the code. It would even told you why it's what you are looking for since the starts.


I suck in python that's why I ask help
This have absolutely nothing to do with Python. Of course it's the language used, but except the network part, everything rely on two elements of Ren'Py's API. And since you're trying to make a real time automatic translation system for Ren'Py game, it's the said Ren'Py's API that you should try to understand, not Python.
 

rackam50

Member
Mar 7, 2018
245
175
result on text
1659281135002.png
Request = Text game/scripts/day1.rpy:17 All characters are over the age of 18. All sexual acts depicted are - despite what may appear at first glance - consensual.
Request = Text game/scripts/day1.rpy:17 All characters are over the age of 18. All sexual acts depicted are - despite what may appear at first glance - consensual.
Request = Text game/scripts/day1.rpy:17 ...
Request = Text game/scripts/day1.rpy:17 First time?
result on menu
1659281540313.png
Request = Text game/scripts/day1.rpy:41 ...
Request = Text game/scripts/day1.rpy:41 ...
Request = Text game/scripts/day1.rpy:41 Good. We can keep it short then.
Request = Text game/scripts/day1.rpy:41 In that case...
Request = Text game/scripts/day1.rpy:41 Censorship: on or off?
Request = Text game/scripts/day1.rpy:41 You need to know a couple of things.
Request = Text game/scripts/day1.rpy:41 You will see the whole thing.
Request = Text game/scripts/day1.rpy:41 We will spare you from the worst of the world.
Request = Text game/scripts/day1.rpy:41 Nos
Request = Text game/scripts/day1.rpy:41 No
Request = Text game/scripts/day1.rpy:41 ...
Request = Text game/scripts/day1.rpy:41 ...
Request = Text game/scripts/day1.rpy:41 Good. We can keep it short then.
Request = Text game/scripts/day1.rpy:41 In that case...
Request = Text game/scripts/day1.rpy:41 Censorship: on or off?
Request = Text game/scripts/day1.rpy:41 You need to know a couple of things.
Request = Text game/scripts/day1.rpy:41 You will see the whole thing.
Request = Text game/scripts/day1.rpy:41 We will spare you from the worst of the world.
Request = Text game/scripts/day1.rpy:41 ...
Request = Text game/scripts/day1.rpy:41 ...
Request = Text game/scripts/day1.rpy:41 Good. We can keep it short then.
Request = Text game/scripts/day1.rpy:41 In that case...
Request = Text game/scripts/day1.rpy:41 Censorship: on or off?
Request = Text game/scripts/day1.rpy:41 You will see the whole thing.things.
Request = Text game/scripts/day1.rpy:41 You will see the whole thing.
Request = Text game/scripts/day1.rpy:41 We will spare you from the worst of the world.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,188
As we would say in French"y a une couille dans le potage"
Lis le putain de manuel, ma biche. (Read the fucking manual, sweetie)
As I said, reading the documentation would have told you way more than your long analyze. And a simple grep would have told you why your server have such results.

The config.say_menu_text_filter callback is used, without a single problem, since years in many incest patches, as well as in many mods. And it works perfectly.
It's called every single time a dialog line, or a menu option, will be displayed, as well as when a dialog line is predicted. What mean that, here again as I said, it's exactly what you were searching from the start.

Instead of having a complicated client-server mechanism, you can do everything directly in this sole callback. And I really mean "everything". You'll catch directly the line to translate, ask for the translation, and directly return the translation for Ren'Py to use it in place of the text originally intended.
Be smart, using a thread, a cache system, and looking at the node type (and content), instead of bothering with its location, and you'll even have a fast and reliable automatic translation mechanism.
 

rackam50

Member
Mar 7, 2018
245
175
The thing is that you did not understand what I wanted to do. (A little bit my fault I didn't explain) My software is used to edit files in the tl folder so I need the name of the file and the line currently displayed. I don't need to predict what's next (for an automatic translation software it would be perfect). For normal text the function I put at the beginning works very well but the problem is when there is a menu I don't know how to get the line of each item
1659290044022.png
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,188
My software is used to edit files in the tl folder so I need the name of the file and the line currently displayed.
No, you don't need the name of the file and the line, this apply only for screens ; and probably also to user defined statements. For the menus and dialog lines, what you need is the magic number corresponding to the said line.

Anyway, if it's what you want, why do you bother with a callback and a client-server model ?

Use unren to extract the rpyc and rpy files, and to get back the rpy files if needed, then ask the SDK to generate the translation files.
Not only you'll have the magic number, but you'll also have all the texts that can be translated. What include part of the screens, if they were correctly designed, and any user defined statements, once again if they were correctly designed.
And since the said translation files include the location of the line as comment, you can still look at the source code to have the context.
 

rackam50

Member
Mar 7, 2018
245
175
No, you don't need the name of the file and the line, this apply only for screens ; and probably also to user defined statements. For the menus and dialog lines, what you need is the magic number corresponding to the said line.
Explain to me how my program will edit a line in a file without knowing the line and the file


Anyway, if it's what you want, why do you bother with a callback and a client-server model ?
why do you bother with a callback :Because I don't know how to do anything else and I'm asking for some assistance on the Renpy side
and a client-server model:why not



Use unren to extract the rpyc and rpy files, and to get back the rpy files if needed, then ask the SDK to generate the translation files.
Not only you'll have the magic number, but you'll also have all the texts that can be translated. What include part of the screens, if they were correctly designed, and any user defined statements, once again if they were correctly designed.
And since the said translation files include the location of the line as comment, you can still look at the source code to have the context.
I took that as sarcasm but I'm not going to recreate something that's already created, it's not creation of tl file I'm doing it's editing
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,188
Explain to me how my program will edit a line in a file without knowing the line and the file
What you want to do is really extremely confusing...

You said that "[your] software is used to edit files in the tl folder". This can mean either filling them (what everyone would expect in such context), and changing their actual content (what you apparently want to do).

But why one would want to do massive change in an already filled tl file ?
The only reason to change the content of a tl file is to correct an error in one, or more, of the translated sentences, what absolutely don't need such complex mechanism. Anyway, what you shown of your software do not fit this proofreading use.

The only possible need for such complex mechanism is to generate a new translation. And, as I said, this is done by firstly asking Ren'Py to generate the tl files for this language.
You'll then have all the translatable sentences (including the ones that can't be caught otherwise) under your eyes, as well as their location in the source code, both as comment. What is all you need to do the translation.
And if really you want to use an online translation service for this, you can directly use those newly generated tl files as input for your own code. Not only it would be way easier, but it would also be done in one pass with something like this:
  • open a tl file
  • load it into an array
  • for i = 0 ; i < size array ; i++
    • skip if line do not starts with /\s+#/
    • skip if line finish by /:\d+\*/
    • catch /^(\s+)#\s+(\S+)\s+['"](.*)['"]$/ <- as it will miss some
    • Translate \3 (the third entity caught by the RegEx)
    • fill array[i+1] with \1 + \2 + translation
  • Open the tl file again.
  • Write the array in it.
If my memory don't betray me, there's even a tool doing this available somewhere in this part of the forum.


why do you bother with a callback :Because I don't know how to do anything else and I'm asking for some assistance on the Renpy side
Have you even read the page of the documentation related to the translation ?


I took that as sarcasm
Sarcastic, me ? It would be known... :whistle:
But the fact is that explaining what one should do to translate a Ren'Py game is nothing near to sarcasm.


but I'm not going to recreate something that's already created, it's not creation of tl file I'm doing it's editing
What lead to three questions:
Firstly, why do you want to mess with the job that someone else did, instead of doing things properly ?
There's a guy/girl/team who've passed days to translate the game in a given language. Please, do not overwrite their work.

Secondly, how will you do if the tl files are only available as rpyc files ?
You'll be facing a bunch of sentences in a language that isn't yours, nor English. And it's all you'll find, because the original sentence, and its location in the source code, are comments, and therefore disappeared.

Thirdly, how will you do if the game is only available in English ?
It represent around 80% of the games available, and also mean that there's no tl files that you'll be able to use.
 

rackam50

Member
Mar 7, 2018
245
175
Precisely this program is for the translators for the games in the course of translation not for the games which do not have translation to see precisely if there are not incoherences between the translated text and the image the translator reads his text and if there is a correction brought instead of being bored to seek in notepad ++ my program posts and edit directly the line
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,188
Precisely this program is for the translators for the games in the course of translation not for the games which do not have translation to see precisely if there are not incoherences between the translated text and the image the translator reads his text and if there is a correction brought instead of being bored to seek in notepad ++ my program posts and edit directly the line

*sight*

Python:
init python:
    def send_to_socket( filename, linenumber, text ):
        [whatever you want, including real time edition of the file]

    renpy.change_language( "french" )
    config.overlay_screens.append( "edit" )

define myEdit = ""

screen edit():
    key "K_e" action [ SetVariable( "myEdit", _last_say_what ), Show( "editor" ) ]

screen editor():
    modal True

    vbox:
        xalign 0.5
        yalign 0.5

        frame:
            xsize int( config.screen_width / 2 )
            ysize int( config.screen_height / 2 )
            input value VariableInputValue( "myEdit" )

        hbox:
            xalign 0.5
            textbutton "Validate":
                action [ Function( send_to_socket, renpy.get_filename_line()[0], renpy.get_filename_line()[1], myEdit ), Hide( "editor" ) ]
            null width 50
            textbutton "Cancel":
                action Hide( "editor" )
Just press the e key when you want to change the text, and "validate" when the change is done.
 

rackam50

Member
Mar 7, 2018
245
175
So it's not bad but it's not exactly what I'm looking for. The editor with this code and internal is what I'm looking to do me is an external editor to make everything easier tags ect... Example select a text put it in red. And I come back to my first question how to get the items of a menu the name of the file the line (item1 file line new ""item2 file line new ""...)
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,188
And I come back to my first question how to get the items of a menu the name of the file the line (item1 file line new ""item2 file line new ""...)
Question that have already been fully answered.