GDNative: How to create a dictionary?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Hartmut Seichter

I cannot figure out for the sake of it how to create a dictionary with the GDNative API … I can do Variants and hand over Arrays, however I need to have a dictionary to hand over key-value pairs.

Me too! I can’t find any tutorials!

RyanJZG | 2018-03-27 10:48

Then please give this question a vote. Otherwise it will sink into oblivion …

Hartmut Seichter | 2018-03-27 11:31

:bust_in_silhouette: Reply From: Bartosz

I didn’t either until I tried searching for it.
First search for “GDNative” in docs gave clue about existence of methods starting with godot_variant and godot_string
Next I go to official repository and search for godot_dictionary gave results

Base on them I’m guessing that to create dictionary you write something similar to this one:

godot_dictionary my_dictionary;


Thanks, I am aware of this. But then, how do I fill in the values?

Hartmut Seichter | 2018-03-27 17:01

based on code of implementation you probably need to convert it to Dictionary e.g. ((Dictionary *)p_self)[key] = value;

Bartosz | 2018-03-27 17:07

Ah. Thanks. Here we go (I’m using the C-API):

void GDAPI godot_dictionary_set(godot_dictionary *p_self, const godot_variant *p_key, const godot_variant *p_value)

In the hope the operator()[key] will create a new key if its not available.


Hartmut Seichter | 2018-03-27 17:11