diff options
Diffstat (limited to 'modules/gdscript/gdscript.cpp')
-rw-r--r-- | modules/gdscript/gdscript.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 563f7e2471..5b0210b16d 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -946,18 +946,29 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) { { const Map<StringName, GDScript::MemberInfo>::Element *E = script->member_indices.find(p_name); if (E) { - if (E->get().setter) { + const GDScript::MemberInfo *member = &E->get(); + if (member->setter) { const Variant *val = &p_value; Variant::CallError err; - call(E->get().setter, &val, 1, err); + call(member->setter, &val, 1, err); if (err.error == Variant::CallError::CALL_OK) { return true; //function exists, call was successful } } else { - if (!E->get().data_type.is_type(p_value)) { - return false; // Type mismatch + if (!member->data_type.is_type(p_value)) { + // Try conversion + Variant::CallError ce; + const Variant *value = &p_value; + Variant converted = Variant::construct(member->data_type.builtin_type, &value, 1, ce); + if (ce.error == Variant::CallError::CALL_OK) { + members.write[member->index] = converted; + return true; + } else { + return false; + } + } else { + members.write[member->index] = p_value; } - members.write[E->get().index] = p_value; } return true; } @@ -2143,7 +2154,8 @@ GDScriptLanguage::GDScriptLanguage() { GLOBAL_DEF("debug/gdscript/completion/autocomplete_setters_and_getters", false); for (int i = 0; i < (int)GDScriptWarning::WARNING_MAX; i++) { String warning = GDScriptWarning::get_name_from_code((GDScriptWarning::Code)i).to_lower(); - GLOBAL_DEF("debug/gdscript/warnings/" + warning, !warning.begins_with("unsafe_")); + bool default_enabled = !warning.begins_with("unsafe_") && i != GDScriptWarning::UNUSED_CLASS_VARIABLE; + GLOBAL_DEF("debug/gdscript/warnings/" + warning, default_enabled); } #endif // DEBUG_ENABLED } |