+3 votes

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.

in Engine by (24 points)

Me too! I can't find any tutorials!

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

1 Answer

+1 vote
Best answer

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;

godot_dictionary_new(&my_dictionary);
by (1,022 points)
selected by

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

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

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.

Thanks!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.