Godot Version
4.6.3
Question
Hey, I’m trying to handle NPC routines in my rpg topdown
It’s not time based like Stardew valley, I can control the story progression myself with a Storyztate singleton.
I already have the routine system working (move, wait, idle, etc). My problem is instancing.
My rooms are dynamically loaded into a currentroom, and npcs aren’t children of the rooms. An npc could be in the kitchen at one story moment, then in the bedroom at another, or not exist at all.
So when I load a room, I need to somehow know which npcs should be instantiated there based on the current story moment, and then give them their routine.
What’s a good way to do that?
My first thought: place the npcs directly into the room scene, but give each npc an @exported Expression that checks if the npc should be there. In the npc’s _ready function, execute the Expression and queue_free the npc if it evaluates to false.
You can also use spawner objects instead of placing the npcs in the room directly.
I assume that your main scene is currentroom and it doesn’t change when you load a room.
So you can handle it on a script attached to currentroom.
One way to do it:
You can have a Dictionary that holds the rooms as keys and Array[NPC] as values. While you progress the story, you change the dictionary accordingly.
And when you load a room, you check this dictionary and load the NPCs that is in the Array.