Page 1 of 1

Export choices

Posted: Wed Apr 18, 2018 9:40 am
by kalesco
Hi, I am very new to Ren'Py and want to achieve something like a learning game for adults working in cultural heritage.
The dialogue and GUI functions are all working nicely and development with Ren'Py is fast.

What I mean to do in addition to let people play an educational game is to use the dialogue system like a survey - this means I need to get the answers of users sent to me.
Is there any way to achieve this, i.e. export the text history? Ideally it would only export the choices, at a time the user decides they want to send the feedback.

I hope you understand what my idea is about and that someone can help me!

(I've tried working with Ink and Unity, but Unity is much too complex to develop a rather simple 2D text adventure)

Thank you!

Re: Export choices

Posted: Thu Apr 19, 2018 4:55 am
by kalesco
Answering my own question:

1) Create a list with choice answers

Code: Select all

label start:
    python:
        choice_list = []

Code: Select all

label question1:
        menu:
            w "Question"
            "Answer":
                $ role = "Answer"
                jump question2
    label question2:
        python:
            choice_list.append("1: "+role)
            ...
            
2) Creating a file and appending the list (not used, maybe for save keeping of stuff)

Code: Select all

init python:
   import codecs
   
for item in choice_list:
	with codecs.open(config.basedir+"/my_file.txt", "a+", "utf-8") as t:
		t.write(item +"\r\n")	
3) sending Email with choices (called when game finishes)

Code: Select all

init python:
	def send_email():
       		body = '%0D'.join(choice_list) #with carriage return for new line
	       import webbrowser
	       webbrowser.open_new("mailto:example@email.com&subject=KuKuRisk-Fragebogen&body="+body)
       

Re: Export choices

Posted: Thu Apr 19, 2018 8:12 am
by xavimat
I use codecs a lot. If you need only the answers in a standard way (for example: 1:a, 2:b, 3:a, 4:c...) you don't need codecs (because there is no need of utf-8), and can use simply with open(...).

You could use another way. RenPy can send info directly to a database:
use urllib2.urlopen (obviously import urllib2), and append the data to it.
You'll need your own hosting with a database, and program a php page to store the info in your database.

Re: Export choices

Posted: Thu Apr 19, 2018 10:14 am
by kalesco
Wow!

Thank you for the DB hint! That would be awesome, I'll check it out!

At the moment I got back to using codecs because the email body string is not working correctly - sometimes it stops. could be because of special characters.
I use codecs because I use full answer strings for the list elements, and the language is German.
Works like a charm. I was not sure how to best send an email with an attachment (my generated txt file) but the database connection might be my saviour!

thanks so much!

Re: Export choices

Posted: Fri Apr 20, 2018 3:22 pm
by xavimat
I was thinking that you don't actually need a database, only a server with php able to send emails.
Make renpy send the info with urllib2.urlopen, and the php receive the info, sanitize the input (htmlentities or so), and build and send an email with the php mail function.

Re: Export choices

Posted: Thu Apr 26, 2018 9:11 am
by kalesco
Thank you xavimat, that was really helpful for the survey response.

For some weird reason I also want to save the full dialogue and choices the user made, to keep for the user - just like they show in delta's readback module.
I see two ways:
a) get what the readback text history shows in a variable and put it into a txt file
b) add the user choices to _history_list

Can anyone help me to achieve either of these, please?