how to take a function from an instance

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

i have an instance

MAGIC_BLAST = loader-> load ("res: //Nodes/Player/Magic/Magic_Blast.tscn", "PackedScene");

Node2D * magic_blast = cast_to <Node2D> (MAGIC_BLAST-> instance ());

in gdscript it would look like this magic_blast.set_magic_blast_direction(1)
but I don’t know how to get a method from this instance in C ++

MAGIC_BLAST = loader-> load ("res: //Nodes/Player/Magic/Magic_Blast.tscn", "PackedScene");

Node2D * magic_blast = cast_to <Node2D> (MAGIC_BLAST-> instance ());
magic_blast.SetMagicBlastDirection(1)

Take notice that the function is in CamelCase

Wakatta | 2021-08-23 22:56

I just looked in Google and found out what CameCase is, but I didn’t understand you a little

F0remNKB | 2021-08-23 23:09

This is C++, not C#.

sash-rc | 2021-08-24 17:42

:bust_in_silhouette: Reply From: sash-rc
// Call by name
magic_blast->call( "set_magic_blast_direction", Array::make(1) );

// or, if your magic_blast is C++ class
CMagicBlast * magic_blast = cast_to <CMagicBlast> (MAGIC_BLAST-> instance ());
magic_blast->set_magic_blast_direction(1); // Normal C++ call

such a question, did you learn all this by reading libraries like Node2D.hpp? there is simply no normal documentation for gdn C ++, you often save me dude

F0remNKB | 2021-08-24 19:05

Well, gdnative requires kind of both experience in Godot and C++.
If you have this, it’s not that hard to figure out. And although C++ documentation is almost non-existent, most of C++ API is reflection of GDScript.

There are some quirks, but than can be googled :slight_smile:

sash-rc | 2021-08-24 20:03