For the sake of testing, this is what I did--it always gave an error just froze.
Code:
m=$game_map.map_id
non_npc_events = [1, 2]
$game_map.events.each_idex do |i|
$game_self_switches[[m, i, 'D']] = true unless non_npc_events.include?(i)
end
Though I ended up implementing the schedule differently, due to the current method having difficulties. Rather than managing the schedule in the NPCs themselves, I simply have a few events that manage their schedules for them. For now, I'm testing it on two NPCs, a mother and daughter, and it seems to be working out pretty well. Outside I have two schedule events.
The event first checks if the current hour matches their waking schedule or sleeping schedule. If it is their waking schedule, their D switch is flipped off and the self switch of the scheduler is set to A. If it is their sleeping hour, their D switch is set on (they disappear) and the self switch of the scheduler is set to B. When the scheduler is set to A, it waits for the hour of her sleeping schedule to come, at which point she will make her way home and disappear. Switch B is turned on and switch A is turned off. When the scheduler is set to B, it waits for the hour of her waking schedule to come, at which point her graphic will change to her normal graphic and she will make her way back to her usual spot before the D switch is flipped off.
Basically, if you transition outside, she will already be where she's supposed to be (inside or out). You won't actually notice the schedule unless you happen to be outside just as it shifts to her transition period. The daughter's is similar, except she wakes up an hour later and goes to sleep two hours earlier. She will walk outside, make a path to her hang out spot and either run around the house or play hopskotch with her little brother until it's time to go in.
There are also schedule events inside, but they do the reverse.
Your second method also gave an error, but the third one did work. I changed it up so it would turn off the A and B switches for all the schedule events, thus resetting them so the characters can be placed where they need to be each time the player enters a new area.
Code:
m=$game_map.map_id
schedule_events = [225, 226]
for i in 0..($game_map.events.length - 1)
$game_self_switches[[m, i, 'A']] = false if schedule_events.include?(i)
$game_self_switches[[m, i, 'B']] = false if schedule_events.include?(i)
end
It's going to take some busy work, but I'm confident now that I can get the schedules set up. Thought I'd share my method in case anyone was interested. I used Theo's Pathfinding and Heirukichi's DayNightCycle to pull it off.
That said, there is a potential minor issue I'm worried about and may have to consider...I'm wondering how this will handle distance. I.e. a shop keeper is supposed to go to bed at 8:00 PM and wake up at 8:00 AM to start shop. If I'm on the other end of town at 8:00 PM, don't enter any buildings, and never go to the shop keepers side until 10:00 AM, will he just walk inside for no reason, then walk back out?
Frankly I'm not too concerned. I really doubt the player is just going to stay in one place for an hour and then happen to stumble across this minor bug. Still, I suppose fixing it could be a little challenge for myself if I ever feel like tackling it.