Re: Reading randomized dialogue from file [SOLVED]
Posted: Tue Jan 24, 2017 12:13 am
Thank you, that was indeed the case. You saved me so much extra work! I feel like a bit of an idiot.
Supporting creators of visual novels and story-based games since 2003.
https://lemmasoft.renai.us/forums/
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
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]"