Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Craft Game |
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);