Skip to content

I don't think on_remove callbacks are working on ArraySchema when using splice #58

Open
@mrosati84

Description

@mrosati84

Hi and first of all THANK YOU for this great project. i love it!

I might have encountered an issue.

I'm running a Defold project, and I'm experiencing an unexpected result when trying to remove an item from ArraySchema using the splice method, as suggested in the documentation.

Here's a snippet of my code of my room state class:

remove_projectile(seq: number) {
    console.log("REMOVE PROJECTILE");
    console.log(seq);

    const index = this.projectiles.findIndex((p) => p.seq == seq);
    this.projectiles.splice(index, 1);
}

this code works like a charm when inspecting the state in Colyseus, however this is not triggering the on_remove on my Defold code:

room.state.projectiles:on_remove(function(projectile, session_id)
    print("PROJECTILE ON REMOVE")
end)

but strangely, this callback in Defold actually works if i use for instance the pop() method in Colyseus (here's the modified code)

remove_projectile(seq: number) {
    console.log("REMOVE PROJECTILE");
    console.log(seq);

    const index = this.projectiles.findIndex((p) => p.seq == seq);
    this.projectiles.pop();
}

of course i can't use pop() for my intent because i need to remove a specific item.

Have i found an issue or am i doing something wrong here?

Thanks!
Matteo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions