From bf1867aaab8d34ee2524f5b703214bb1c2684eb7 Mon Sep 17 00:00:00 2001 From: m Date: Mon, 30 Jul 2018 00:04:32 -0400 Subject: 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. --- core/variant_call.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/variant_call.cpp') diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 8693a584f2..18b4977feb 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -486,6 +486,7 @@ struct _VariantCall { VCALL_LOCALMEM0R(Dictionary, keys); VCALL_LOCALMEM0R(Dictionary, values); VCALL_LOCALMEM1R(Dictionary, duplicate); + VCALL_LOCALMEM2R(Dictionary, get); VCALL_LOCALMEM2(Array, set); VCALL_LOCALMEM1R(Array, get); @@ -1679,6 +1680,7 @@ void register_variant_methods() { ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, keys, varray()); ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, values, varray()); ADDFUNC1R(DICTIONARY, DICTIONARY, Dictionary, duplicate, BOOL, "deep", varray(false)); + ADDFUNC2R(DICTIONARY, NIL, Dictionary, get, NIL, "key", NIL, "default", varray(Variant())); ADDFUNC0R(ARRAY, INT, Array, size, varray()); ADDFUNC0R(ARRAY, BOOL, Array, empty, varray()); -- cgit v1.2.3