Fix condition saving the variable too soon

This commit is contained in:
Ruben van de Ven 2019-06-15 20:10:53 +02:00
parent b25d7dd6d5
commit 16fbee7555

View file

@ -452,17 +452,16 @@ class Condition(object):
capturedVariables = result.groupdict() capturedVariables = result.groupdict()
if ('instantMatch' in self.vars and self.vars['instantMatch']) or not r.isSpeaking():
# try to avoid setting variables for intermediate strings
for captureGroup in capturedVariables:
story.setVariableValue(captureGroup, capturedVariables[captureGroup])
if 'instantMatch' in self.vars and self.vars['instantMatch']: if 'instantMatch' in self.vars and self.vars['instantMatch']:
story.logger.info(f"Instant match on {self.vars['regex']}, {self.vars}") story.logger.info(f"Instant match on {self.vars['regex']}, {self.vars}")
self.logInfo = "Instant match of {}, captured {}".format( self.logInfo = "Instant match of {}, captured {}".format(
self.vars['regex'], self.vars['regex'],
capturedVariables capturedVariables
) )
# Set variables only when direction returns true
if capturedVariables is not None:
for captureGroup in capturedVariables:
story.setVariableValue(captureGroup, capturedVariables[captureGroup])
return True return True
# TODO: implement 'instant match' -> don't wait for isFinished() # TODO: implement 'instant match' -> don't wait for isFinished()