Skip to content

Commit

Permalink
Fixed '_owner' parameter in FAQ/EntityFactory (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuto193 committed Jun 16, 2022
1 parent cd721b4 commit b7db212
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/faq/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ struct EntityFactory {}
#[methods]
impl EntityFactory {
#[export]
fn enemy(&self, _owner: &Object, name: String, health: f32)
fn enemy(&self, _owner: &Reference, name: String, health: f32)
-> Instance<Enemy, Unique> {
Enemy { name, health }.emplace()
}
Expand Down Expand Up @@ -286,12 +286,12 @@ impl AnotherNativeScript {
.expect("Failed to convert my_node variant to object")
.assume_safe()
};

// 2. Obtain a TInstance which gives access to the Rust object's data.
let my_node = my_node
.cast_instance::<MyNode2D>()
.expect("Failed to cast my_node object to instance");

// 3. Map over the RefInstance to process the underlying user data.
my_node
.map(|my_node, _owner| {
Expand Down Expand Up @@ -390,7 +390,7 @@ You would need to use the following code.
#[no_constructor]
struct MyNode {
// late-initialization is modeled with Option
// the Default derive will initialize both to None
// the Default derive will initialize both to None
node2d: Option<Ref<Node>>,
instance: Option<Ref<MyClass>>,
}
Expand All @@ -406,7 +406,7 @@ impl MyNode {
let node2d = unsafe { node2d.assume_safe() };
let node2d = node2d.cast::<Node2D>();
self.node2d = Some(node2d.claim());

// Get an existing child node that is a Rust class.
let instance = owner
.get_node("MyClass")
Expand Down

0 comments on commit b7db212

Please sign in to comment.