How do you declare/init a new Label Node from Nativescript 1.1/Godot 3.1 Beta?

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

For Nativescript 1.1/Godot 3.1 Beta1 I can’t get the following to work, p_child always ends up null:

Label *nlabel = new Label();
get_parent())->add_child(nlabel, true );

The exact error msg in 1.1/godot beta 1 is:

ERROR: add_child: Parameter ' p_child ' is null.
   At: scene/main/node.cpp:1127

Saw in Label.hpp that this:

static void *operator new(size_t);
static void operator delete(void *);

was changed to:

  static Label *_new();

Had the following working in Nativescript 1.0/Godot 3.0:

Label *nlabel = new Label();
((Label *)owner->get_parent())->add_child(nlabel, true );
nlabel->set_text("This is a Label node added dynamically from GDNative C++");
nlabel->set_scale(Vector2(2,2));
nlabel->set_name("myLabelAddedFromC++");

What is the correct way to declare and init a Label?
btw this is a script dropped on the sprite from the tutorial for GDNative
http://docs.godotengine.org/en/latest/tutorials/plugins/gdnative/gdnative-cpp-example.html

Any help appreciated! :slight_smile:
Quote

:bust_in_silhouette: Reply From: aurodev

UPDATE
As was pointed out on Github the new way to declare this is Class::_new() so this becomes:

Label *nlabel = Label::_new(); 
get_parent()->add_child(nlabel);