random gen and extracting text results

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
cedes
Regular
Posts: 44
Joined: Fri Aug 04, 2017 3:33 pm
itch: cedes
Contact:

random gen and extracting text results

#1 Post by cedes »

I've been experimenting with random generating in renpy, I was wondering if I could extract the text results? Preferably what the the text says on the screen, rather than the exact code, but I'll take either.

Basically

Code: Select all

"My name is [first_name] [last_name] I am [age], and I'm starting my life as [job]."
the text input would be random.choice and random.randint, with more information and such. Could I have the text come out like

Code: Select all

"My name is Bob Bobber I am 1, and I'm starting my life as a robot."
The code would keep changing as the game progresses but I'd love to have something more than just a screenshot to refer to!

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: random gen and extracting text results

#2 Post by kivik »

When you say extract do you mean export it outside of Ren'py? Since you mentioned screenshot.

If you just want a static version of the sentence you can always use:

Code: Select all

sentence = "My name is %s %s I am %s, and I'm starting my life as %s." % (first_name, last_name, age, job)
renpy.say(who, sentence)
If you want to extract the text as well, you can use python functions:

Code: Select all

file = open(config.savedir + 'export.txt', 'w+')
file.write(sentence)
file.close()
I used the config.savedir because I get a permission denied error otherwise. You can output the variable onscreen to help you see where it's located.

Hope that's what you meant, I'm not 100% sure!

User avatar
cedes
Regular
Posts: 44
Joined: Fri Aug 04, 2017 3:33 pm
itch: cedes
Contact:

Re: random gen and extracting text results

#3 Post by cedes »

Ah yes I believe that's what I meant! And where should I put the python code? After all this time on renpy I barely know much code even less about python haha!

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: random gen and extracting text results

#4 Post by kivik »

The first part you'd put just before you first use the sentence - you'll need to substitute the "who" part of the renpy.say function with whichever character is speaking. It basically creates a string of your sentence and stays the same for the remaining time in the game unless you change it.

The exporting part of the code can come straight after.

Since they're all python statements, you'll want to put it inside a python: block

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]