diff --git a/CHANGELOG.md b/CHANGELOG.md index 84a8afba69..926fea3995 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,15 @@ instead of 'Custom' (InspectorCaracal) - [Fix][pull3274]: Traceback when creating objects with initial nattributes (InspectorCaracal) +- [Fix][issue3272]: Make sure `ScriptHandler.add` does not fail if passed an + instantiated script. - Docs: Typo fixes and starting earlier with explaining how to add to the default cmdsets. [pull3267]: https://github.com/evennia/evennia/pull/3267 [pull3270]: https://github.com/evennia/evennia/pull/3270 [pull3274]: https://github.com/evennia/evennia/pull/3274 +[issue3272]: https://github.com/evennia/evennia/issues/3272 ## Evennia 2.3.0 diff --git a/evennia/scripts/scripthandler.py b/evennia/scripts/scripthandler.py index 406e2f4322..553834b911 100644 --- a/evennia/scripts/scripthandler.py +++ b/evennia/scripts/scripthandler.py @@ -76,10 +76,14 @@ class ScriptHandler(object): script = create.create_script( scriptclass, key=key, account=self.obj, autostart=autostart ) - else: - # adding to an Object. We wait to autostart so we can differentiate - # a failing creation from a script that immediately starts/stops. + elif isinstance(scriptclass, str) or callable(scriptclass): + # a str or class to use create before adding to an Object. We wait to autostart + # so we can differentiate a failing creation from a script that immediately starts/stops. script = create.create_script(scriptclass, key=key, obj=self.obj, autostart=False) + else: + # already an instantiated class + script = scriptclass + if not script: logger.log_err(f"Script {scriptclass} failed to be created.") return None