colyseus / colyseus-defold

⚔ Colyseus SDK for Defold Engine
https://docs.colyseus.io/getting-started/defold-client/
MIT License
60 stars 10 forks source link

on_remove only called once #47

Closed tufcode closed 11 months ago

tufcode commented 11 months ago

on_remove never gets called after the first remove.

Schema

@type([GameObject]) gameObjects = new ArraySchema<GameObject>();

Room (on simulation tick)

// Remove all game objects
this.state.gameObjects.clear();
// Add new objects here...

Client

room.state.gameObjects:on_add(function(object, key)
    print("on_add", object, key)
end)

room.state.gameObjects:on_remove(function(object, key)
    print("on_remove", object, key)
end)

Result

DEBUG:SCRIPT: on_add table: 0x0193bbdeac30 1 DEBUG:SCRIPT: on_remove table: 0x0193bbdeac30 1 DEBUG:SCRIPT: on_add table: 0x0193bd43ba30 2 DEBUG:SCRIPT: on_add table: 0x0193bd434920 3 DEBUG:SCRIPT: on_add table: 0x0193bbe221e0 4 DEBUG:SCRIPT: on_add table: 0x0193bbde0320 5

endel commented 11 months ago

Hi @tufcode, can you share your project with me? I couldn't reproduce it here:

    this.state.gameObjects.push(new GameObject().assign({ value: "One" }));
    this.state.gameObjects.push(new GameObject().assign({ value: "Two" }));
    this.state.gameObjects.push(new GameObject().assign({ value: "Three" }));
    this.state.gameObjects.push(new GameObject().assign({ value: "Four" }));

    // clearing messages
    this.clock.setTimeout(() => {
      this.state.gameObjects.clear();
      this.state.gameObjects.push(new GameObject().assign({ value: "Five" }));
      this.state.gameObjects.push(new GameObject().assign({ value: "Six" }));
    }, 2000);
DEBUG:SCRIPT: added One
DEBUG:SCRIPT: added Two
DEBUG:SCRIPT: added Three
DEBUG:SCRIPT: added Four
DEBUG:SCRIPT: removed   One 
DEBUG:SCRIPT: removed   Two 
DEBUG:SCRIPT: removed   Three   
DEBUG:SCRIPT: removed   Four    
DEBUG:SCRIPT: added Five
DEBUG:SCRIPT: added Six