0 votes

so i tried to set a text in a label node from another node in rust but for some reason its says

error[E0599]: no method named `set_text` found for enum `Option<TRef<'_, gdnative::prelude::Label>>` in the current scope
  --> src/lib.rs:24:73
   |
24 |             owner.get_node("Node/Label2").unwrap().assume_safe().cast::<Label>().set_text("_process (rust)\ndelta = {}")
   |                                                                                  ^^^^^^^^ method not found in `Option<TRef<'_, gdnative::prelude::Label>>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
error: could not compile `godot`

To learn more, run the command again with --verbose.

here is my code

use gdnative::prelude::*;

#[derive(NativeClass)]
#[inherit(Spatial)]
pub struct HelloWorld;

#[methods]
impl HelloWorld {
//  let test:str = "rust"

    fn new(_owner: &Spatial) -> Self {
        HelloWorld
    }

    #[export]
    fn _ready(&self, _owner: &Spatial) {
        godot_print!("_ready (rust)");
    }
    #[export]
    fn _process(&self, owner: &Spatial, delta: f64){
        godot_print!("_process (rust)\ndelta = {}", delta);
//      owner.get_node("Node/Label2").unwrap().cast::<Ref<Label>>().set_text("_process (rust)\ndelta = {}")
        unsafe {
            owner.get_node("Node/Label2").unwrap().assume_safe().cast::<Label>().set_text("_process (rust)\ndelta = {}")
        }
    }
}

fn init(handle: InitHandle) {
    handle.add_tool_class::<HelloWorld>();
}

godot_init!(init);
Godot version 3.2.3
in Engine by (16 points)

Please log in or register to answer this question.

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.