diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/variant.h | 2 | ||||
-rw-r--r-- | core/variant_call.cpp | 12 |
2 files changed, 11 insertions, 3 deletions
diff --git a/core/variant.h b/core/variant.h index b8b028a760..90be593bd9 100644 --- a/core/variant.h +++ b/core/variant.h @@ -426,7 +426,7 @@ public: static void get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_list); static void get_numeric_constants_for_type(Variant::Type p_type, List<StringName> *p_constants); static bool has_numeric_constant(Variant::Type p_type, const StringName& p_value); - static int get_numeric_constant_value(Variant::Type p_type, const StringName& p_value); + static int get_numeric_constant_value(Variant::Type p_type, const StringName& p_value,bool *r_valid=NULL); typedef String (*ObjectDeConstruct)(const Variant& p_object,void *ud); typedef void (*ObjectConstruct)(const String& p_text,void *ud,Variant& r_value); diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 069c20bc6e..5337b6ba04 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -1324,14 +1324,22 @@ bool Variant::has_numeric_constant(Variant::Type p_type, const StringName& p_val return cd.value.has(p_value); } -int Variant::get_numeric_constant_value(Variant::Type p_type, const StringName& p_value) { +int Variant::get_numeric_constant_value(Variant::Type p_type, const StringName& p_value, bool *r_valid) { + + if (r_valid) + *r_valid=false; ERR_FAIL_INDEX_V(p_type,Variant::VARIANT_MAX,0); _VariantCall::ConstantData& cd = _VariantCall::constant_data[p_type]; Map<StringName,int>::Element *E = cd.value.find(p_value); - ERR_FAIL_COND_V(!E,0); + if (!E) { + return -1; + } + if (r_valid) + *r_valid=true; + return E->get(); } |