carenalgas / popochiu

Godot plugin to make point-and-click adventure games, inspired by tools like Adventure Game Studio and PowerQuest.
https://carenalgas.github.io/popochiu/
MIT License
207 stars 19 forks source link

Characters don't get deleted when changing rooms #345

Open balloonpopper opened 1 week ago

balloonpopper commented 1 week ago

Bug description

Characters don't get deleted when changing rooms and appear in the next room when they haven't been included in that room. It is related to the room not having the "Script name" property set.

Steps to reproduce

Have 2 rooms where RoomA connects to RoomB. RoomA should have some characters added to it. RoomB should not have the characters added to it. Do not set the "script_name" for the parent node of either room. Play the game and go from RoomA to RoomB, the characters from RoomA will be instantiated in RoomB.

Expected vs observed behavior

Characters shouldn't appear in a room they haven't been included in.

Environment information (please complete):

Additional context

After some investigation, what appears to happen is that this code runs in the goto_room function (i_room.gd): (line 166)

    if store_state:
        rooms_states[current.script_name] = current.state
        current.state.save_children_states()

If the parent node of the room does not have a script name set, then it gets the value of the destination room. This means that if you're going from RoomA -> RoomB, this store state code stores RoomA's state in the dictionary 'room_states["RoomB"]'. Afterwards, when RoomB is instantated, the code in the "room_readied" function runs and the code on line ~239-255 recreates RoomA's characters in RoomB.

    for chr_script_name: String in rooms_states[room.script_name]["characters"]:
        <...>
        current.add_character(chr)