From 02f585973ca469d8079cb80884bef9bd11f63ebd Mon Sep 17 00:00:00 2001 From: ryo_saeba Date: Sun, 27 Dec 2020 13:07:28 +0000 Subject: [PATCH] Fix script conditions, round 2. git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@21648 282e977c-c81d-0410-88c4-b93c2d0d6712 --- python/CFDialog.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/python/CFDialog.py b/python/CFDialog.py index eb56d0a0e..9c9c044fc 100644 --- a/python/CFDialog.py +++ b/python/CFDialog.py @@ -268,12 +268,14 @@ class Dialog: for condition in rule.getPreconditions(): action = condition[0] args = condition[1:] + script_args = {'args': args, 'character': character, 'location': location, 'action': action, 'self': self} path = os.path.join(Crossfire.DataDirectory(), Crossfire.MapDirectory(), 'python/dialog/pre/', action + '.py') if os.path.isfile(path): try: - exec(open(path).read(), globals()) - except: - Crossfire.Log(Crossfire.LogError, "CFDialog: Failed to evaluate condition %s." % condition) + exec(open(path).read(), {}, script_args) + verdict = script_args['verdict'] + except Exception as ex: + Crossfire.Log(Crossfire.LogError, "CFDialog: Failed to evaluate condition %s: %s." % (condition, str(ex))) verdict = False if verdict == False: return 0