Reading randomized dialogue from file [SOLVED]
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.
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.
-
- Newbie
- Posts: 7
- Joined: Mon Jun 27, 2016 5:00 pm
- Contact:
Re: Reading randomized dialogue from file [SOLVED]
Thank you, that was indeed the case. You saved me so much extra work! I feel like a bit of an idiot.
- Steffenator
- Regular
- Posts: 53
- Joined: Fri Feb 17, 2017 11:58 am
- Contact:
Re: Reading randomized dialogue from file [SOLVED]
I keep getting the same issue, it happens in random places in my dialogue.
It started after the 6.99.12.3 update.
Here's my log.
It started after the 6.99.12.3 update.
Here's my log.
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/lstare01.rpy", line 32, in script
me "I'm not sure, but...\nIf I'd known my cousin had such an attractive roomate, I would have stopped by months ago."
KeyError: u'playername'
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/lstare01.rpy", line 32, in script
me "I'm not sure, but...\nIf I'd known my cousin had such an attractive roomate, I would have stopped by months ago."
File "C:\Users\Jared\Desktop\XFer\renpy-6.99.12.2\renpy\ast.py", line 613, in execute
renpy.exports.say(who, what, interact=self.interact)
File "C:\Users\Jared\Desktop\XFer\renpy-6.99.12.2\renpy\exports.py", line 1147, in say
who(what, interact=interact)
File "C:\Users\Jared\Desktop\XFer\renpy-6.99.12.2\renpy\character.py", line 855, in __call__
who = who_pattern.replace("[who]", sub(who))
File "C:\Users\Jared\Desktop\XFer\renpy-6.99.12.2\renpy\character.py", line 850, in sub
return renpy.substitutions.substitute(s, scope=scope, force=force, translate=translate)[0]
File "C:\Users\Jared\Desktop\XFer\renpy-6.99.12.2\renpy\substitutions.py", line 232, in substitute
s = formatter.vformat(s, (), kwargs)
File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 563, in vformat
File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 585, in _vformat
File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 646, in get_field
File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 605, in get_value
KeyError: u'playername'
Windows-7-6.1.7601-SP1
Ren'Py 6.99.12.3.2123
Just_Visiting 1.0
-
- Newbie
- Posts: 5
- Joined: Mon Jul 02, 2018 5:38 pm
- Contact:
Re: Reading randomized dialogue from file [SOLVED]
Sorry to resurrect this thread, not sure of the correct etiquette -- anyway, it seemed to work at first but every time I insert "[justOneLineToSay]" for a character's dialogue, it just picks the same exact line from the questions.txt file, with no randomizing going on during any subsequent uses. If I relaunch the project, it'll pick a different random line but again just the same one over and over. Any suggestions on how I can get a different line each time the command is used?
Also -- What are the specifications for the external text file to work properly? Some lines just result in bugs until I edit them out, with no seeming rhyme or reason to it. I'm missing something incredibly obvious, and would super appreciate someone setting me straight!
Also -- What are the specifications for the external text file to work properly? Some lines just result in bugs until I edit them out, with no seeming rhyme or reason to it. I'm missing something incredibly obvious, and would super appreciate someone setting me straight!
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Reading randomized dialogue from file [SOLVED]
Using @property in an object is likely your best bet so as to force the interpolation to recall random...
Note the !q which will help with lines including {, [, and quotes
Also note I opted to shuffle the lines so repeat calls do not accidentally repeat the same line (until lines exhausted)
Code: Select all
init python:
class RandomReply(object):
def __init__(self, filename=None):
with renpy.file(filename) as f:
self.lines = f.readlines()
renpy.python.rng.shuffle( self.lines )
@property
def line(self):
return self.lines.pop() if self.lines else "No quotes left."
reply = RandomReply("quotes.txt")
label start:
e "[reply.line!q]"
Also note I opted to shuffle the lines so repeat calls do not accidentally repeat the same line (until lines exhausted)
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
-
- Newbie
- Posts: 5
- Joined: Mon Jul 02, 2018 5:38 pm
- Contact:
Re: Reading randomized dialogue from file [SOLVED]
Perfect! Now it's randomizing properly from the hundreds of weird gibberish lines in the txt file. Thank you so much for pointing out "!q," missed that completely. Is there anything else to keep in mind with the formatting on the text file so everything works properly without squares being thrown in there?
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Reading randomized dialogue from file [SOLVED]
Try:
return unicode(self.lines.pop()).encode('utf-8').replace("\r", "") if self.lines else "No quotes left."
Not going to manage any non unicode characters mid string though. For those you'd have to either edit the file or do more replaces.
return unicode(self.lines.pop()).encode('utf-8').replace("\r", "") if self.lines else "No quotes left."
Not going to manage any non unicode characters mid string though. For those you'd have to either edit the file or do more replaces.
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
-
- Newbie
- Posts: 5
- Joined: Mon Jul 02, 2018 5:38 pm
- Contact:
Re: Reading randomized dialogue from file [SOLVED]
That sorted it! Now to prevent myself from going overboard and abusing this.
Too late!
Too late!
Re: Reading randomized dialogue from file [SOLVED]
Wow! Thank you!
Renpy textbook (in Russian). https://disk.yandex.ru/i/httNEajU7iFWHA (all information is out of date) Update 22.06.18
Sawa - a game of the Drow Nation
Honest Critique
Poses in visual novels, or how to hold a character properly in the frame
Help save articles to the webarchive. [/color]
Sawa - a game of the Drow Nation
Honest Critique
Poses in visual novels, or how to hold a character properly in the frame
Help save articles to the webarchive. [/color]
Who is online
Users browsing this forum: Stampaw