ID:2176083
 
(See the best response by Kaiochao.)
Okay, so I have monster AI that I possibly wanted to turn off when no players are in the map and spawn points to cycle through so I have some questions in terms of function and efficiency.

Is the way to do this make the default area:
on Entered() cycle through all monsters and compare Z value to turn
on Exited() check all other players for Z value of the map left to see if anyone is still there and if not turn off stuff?

Should I have spawn points tick down a timer for every monster then spawn it or have one timer cycle through a bunch of spawn points on a more frequent basis?

I would have turned these into two different posts, but I am constantly asking questions and I didn't know if I was being overbearing. Thanks to the community for keeping me going in my projects!

Best response
To the first question: that's a good start. The rule you're trying to implement is "NPCs are active only when in view of any player". One problem that can arise from depending on area.Entered() and area.Exited() is when a mob moves without calling those procs, which is when you set the mob's positional variables (e.g. loc, x, y, etc.) directly, or you "del" the mob.

To the second question: I prefer a single game loop instead of a bunch of separate loops. It turns out to be more efficient, probably because there are fewer active procs running, or something.
In response to Kaiochao
Kaiochao wrote:
I prefer a single game loop instead of a bunch of separate loops. It turns out to be more efficient, probably because there are fewer active procs running, or something.

Same, I think it's because of the overhead.

Thank you for your answer. I am grateful for all of the community's response and support. I'm going to start tackling some of this stuff because I really want a complete game for once instead of another half project. Happy Coding all! :D
In response to Kaiochao
Kaiochao wrote:
To the second question: I prefer a single game loop instead of a bunch of separate loops. It turns out to be more efficient, probably because there are fewer active procs running, or something.

Proc calling and teardowns--and the same applies to sleeping and waking--have a certain amount of overhead associated with them. What can be done in one proc instead of 100 is better.

That said, polymorphism is still important. It probably makes sense for AI calls on a monster to still belong to that monster type, and that sort of thing. Single-proc handling of multiple items makes more sense when all of those items are the same in some significant way, like for instance processing a bunch of floor spikes at once.
In response to Lummox JR
Makes sense lummox, because doing the spawn points in one giant loop seems effective, but doing the AI in one loop makes them all react at the same time which is rather robotic. So I winded up leaving them on individual timer for AI even though they still refer to their own On & Off switch depending on player presence.
In response to Zamargo
Sounds like a good plan. If AIs are only active when players are in a certain range or under certain conditions, then you'll only have a certain number active at once (per player, anyway), and that should be plenty reasonable.