How to save dialogs to a text file on a server?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Prandygame
Newbie
Posts: 16
Joined: Tue Oct 06, 2020 10:10 pm
Completed: Romance Dimensional
Projects: Romance Dimensional 2
Organization: Prandy Game
itch: prandygame.itch.io
Contact:

How to save dialogs to a text file on a server?

#1 Post by Prandygame » Sat Oct 31, 2020 4:56 pm

Resolved #### Hello, it is my first topic here, I await your help, I do not speak English so I hope you understand the translation, I would like the player to save the active dialog in a text file using a button, the text file is saved with a Different name depending on the language of the game, if it is in English it would be like English_correction.txt, if it is Russian, Russian_correction.txt and so on etc, I have some information about what I could use but I don't know how to do it.

Code: Select all

 _history_list[-1].what   #I think this saves the dialogs.

    python:
        try: renpy.file(config.basedir + "/English_correction.txt")
        except: open(config.basedir + "/English_correction.txt", "wb").write(renpy.file("English_correction.txt").read())
matter resolved
##############

Thanks to a friend you can get the following, and I want to share it if you are interested, this consists of placing a small button next to the dialog to report bad translations of the game, the active dialog is sent to a server created in
https://www.000webhost.com/?__cf_chl_js ... Puh5O4p-Mk
in this a .php file is created in the public_html folder and the following code is placed.

Code: Select all

<?php

$txt = htmlspecialchars($_POST['txt']);
$lang = htmlspecialchars($_POST['lang']);
$user = htmlspecialchars($_POST['user']);

if ($lang === "english") {
    $myfile = fopen("../errors_english.txt", "a");
} elseif ($lang === "francais") {
    $myfile = fopen("../errors_francais.txt", "a");
} elseif ($lang === "portugues") {
    $myfile = fopen("../errors_portugues.txt", "a");
} else {
    $myfile = fopen("../errors_espanol.txt", "a");
}

fwrite($myfile, $user.":".$txt."\n");
fclose($myfile);
This serves so that the players can contribute to improve the translations, in this case it only works for 4 languages, English, French, Spanish, Portuguese, the names of the language folders must be put in the code, the files with the wrong translations it is generated in the root folder of the server.

you put this code there, with the link of your server.
And the name of the PHP file that you created in the same link

Code: Select all

init python:
    from urllib import urlencode
    from urllib2 import urlopen
    if not persistent.user:
        import uuid
        persistent.user = str(uuid.uuid4())[:10]
    def report_error(txt):
        data = {}
        data["lang"] = _preferences.language
        data["txt"] = txt
        data["user"] = persistent.user
        data = urlencode(data)
        try:
            urlopen("http://your_server.000webhostapp.com/filename.php", data=data, timeout=10)
        except:
            pass
You insert in the screen script, in the screen say, an image button or whatever you want.

Code: Select all

screen say(who, what):
    style_prefix "say"
    vbox:

        align (1.0, 1.0)
        imagebutton idle ("tra_ground") action [Function(report_error, what), Play("sound","gui/sonido1/boton_1.mp3")] hover("tra_hover")

    window:
        id "window"

        if who is not None:

            window:
                id "namebox"
                style "namebox"
                text who id "who"

        text what id "what"
Last edited by Prandygame on Sun Nov 01, 2020 3:16 pm, edited 2 times in total.
My first game made in Renpy check it out.
https://prandygame.itch.io/visual-novel-romance

User avatar
Vladya
Regular
Posts: 34
Joined: Sun Sep 20, 2020 3:16 am
Github: NyashniyVladya
Contact:

Re: How to save dialogues to a text file?

#2 Post by Vladya » Sat Oct 31, 2020 7:19 pm

May I clarify what exactly you want? I didn't quite understand it from the description.
  • Save every line, replacing the previous one?
  • Save the entire dialog shown at the moment, updating it with every new line?
  • Save all the existing text in the game?
  • Simply save the contents of the "_history_list" variable to a file?
  • Something else?

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: How to save dialogues to a text file?

#3 Post by Per K Grok » Sun Nov 01, 2020 7:42 am

Prandygame wrote:
Sat Oct 31, 2020 4:56 pm
Hello, it is my first topic here, I await your help, I do not speak English so I hope you understand the translation, I would like the player to save the active dialog in a text file using a button, the text file is saved with a Different name depending on the language of the game, if it is in English it would be like English_correction.txt, if it is Russian, Russian_correction.txt and so on etc, I have some information about what I could use but I don't know how to do it.

Code: Select all

 _history_list[-1].what   #I think this saves the dialogs.

    python:
        try: renpy.file(config.basedir + "/English_correction.txt")
        except: open(config.basedir + "/English_correction.txt", "wb").write(renpy.file("English_correction.txt").read())


This code will save the present history log in a text document "history.txt" on pressing button "w", if "screen historyWrite" is shown.

Code: Select all

init python:
    def writehistory():
        f = open("history.txt", "w")
        for x in _history_list:
            f.write(x.what + "\n")
        f.close()
        renpy.notify("History file saved.")


screen historyWrite():
    key "w" action Function(writehistory)

User avatar
Prandygame
Newbie
Posts: 16
Joined: Tue Oct 06, 2020 10:10 pm
Completed: Romance Dimensional
Projects: Romance Dimensional 2
Organization: Prandy Game
itch: prandygame.itch.io
Contact:

Re: How to save dialogues to a text file?

#4 Post by Prandygame » Sun Nov 01, 2020 3:14 pm

Per K Grok wrote:
Sun Nov 01, 2020 7:42 am
Prandygame wrote:
Sat Oct 31, 2020 4:56 pm
Hello, it is my first topic here, I await your help, I do not speak English so I hope you understand the translation, I would like the player to save the active dialog in a text file using a button, the text file is saved with a Different name depending on the language of the game, if it is in English it would be like English_correction.txt, if it is Russian, Russian_correction.txt and so on etc, I have some information about what I could use but I don't know how to do it.

Code: Select all

 _history_list[-1].what   #I think this saves the dialogs.

    python:
        try: renpy.file(config.basedir + "/English_correction.txt")
        except: open(config.basedir + "/English_correction.txt", "wb").write(renpy.file("English_correction.txt").read())


This code will save the present history log in a text document "history.txt" on pressing button "w", if "screen historyWrite" is shown.

Code: Select all

init python:
    def writehistory():
        f = open("history.txt", "w")
        for x in _history_list:
            f.write(x.what + "\n")
        f.close()
        renpy.notify("History file saved.")


screen historyWrite():
    key "w" action Function(writehistory)
Thanks, they already helped me, leave the information in case someone is interested.
My first game made in Renpy check it out.
https://prandygame.itch.io/visual-novel-romance

Post Reply

Who is online

Users browsing this forum: Bing [Bot]