From 2d8f6c1b1d984222d1690f8afd504faed9f303be Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Thu, 18 Jul 2024 16:42:54 +0300 Subject: [PATCH] GDScript: Fix message when calling non-tool function in tool mode --- core/object/script_language.cpp | 12 ++++ core/object/script_language.h | 5 +- modules/gdscript/gdscript_function.h | 2 +- modules/gdscript/gdscript_vm.cpp | 85 ++++++++++++++-------------- 4 files changed, 57 insertions(+), 47 deletions(-) diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index cdc56e5ec51..0428caa80d0 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -704,6 +704,18 @@ bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const { return false; } +Variant PlaceHolderScriptInstance::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; +#if TOOLS_ENABLED + if (Engine::get_singleton()->is_editor_hint()) { + return String("Attempt to call a method on a placeholder instance. Check if the script is in tool mode."); + } else { + return String("Attempt to call a method on a placeholder instance. Probably a bug, please report."); + } +#endif + return Variant(); +} + void PlaceHolderScriptInstance::update(const List &p_properties, const HashMap &p_values) { HashSet new_values; for (const PropertyInfo &E : p_properties) { diff --git a/core/object/script_language.h b/core/object/script_language.h index 59a43a7b297..e38c344ae57 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -454,10 +454,7 @@ public: return 0; } - virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; - return Variant(); - } + virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override; virtual void notification(int p_notification, bool p_reversed = false) override {} virtual Ref