From 16fbee75556a1dcb6dc0fc6c1c231cc43e5e12b0 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Sat, 15 Jun 2019 20:10:53 +0200 Subject: [PATCH] Fix condition saving the variable too soon --- hugvey/story.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hugvey/story.py b/hugvey/story.py index 92754d1..4ccabab 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -452,17 +452,16 @@ class Condition(object): 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']: story.logger.info(f"Instant match on {self.vars['regex']}, {self.vars}") self.logInfo = "Instant match of {}, captured {}".format( self.vars['regex'], capturedVariables ) + # Set variables only when direction returns true + if capturedVariables is not None: + for captureGroup in capturedVariables: + story.setVariableValue(captureGroup, capturedVariables[captureGroup]) return True # TODO: implement 'instant match' -> don't wait for isFinished()