summaryrefslogtreecommitdiffstats
path: root/core/dictionary.cpp
diff options
context:
space:
mode:
authorm <malcolm.g.howard@gmail.com>2018-07-30 00:04:32 -0400
committerm <malcolm.g.howard@gmail.com>2018-11-19 14:03:13 -0500
commitbf1867aaab8d34ee2524f5b703214bb1c2684eb7 (patch)
tree8a7bb25d39118e5f933d815e3533f6ddaace4eb6 /core/dictionary.cpp
parent451e5fd0511bc2c17a66fc73a0de9a5169109517 (diff)
downloadredot-engine-bf1867aaab8d34ee2524f5b703214bb1c2684eb7.tar.gz
Added Python-like .get() method to Dictionary in GDScript #20488
Added .get() method to Dictionary class in GDScript to return the value if the key exists, or return Null if the key does not exist.
Diffstat (limited to 'core/dictionary.cpp')
-rw-r--r--core/dictionary.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/core/dictionary.cpp b/core/dictionary.cpp
index ccbdff3816..6a3ab82879 100644
--- a/core/dictionary.cpp
+++ b/core/dictionary.cpp
@@ -112,6 +112,15 @@ Variant Dictionary::get_valid(const Variant &p_key) const {
return E.get();
}
+Variant Dictionary::get(const Variant &p_key, const Variant &p_default) const {
+ const Variant *result = getptr(p_key);
+ if (!result) {
+ return p_default;
+ }
+
+ return *result;
+}
+
int Dictionary::size() const {
return _p->variant_map.size();