How to wait for all NPCs on map without slow down?

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

How to wait for all NPCs on map without slow down?

Post by sheamkennedy »

I noticed in the dictionary that "wait for all" doesn't properly wait for all NPCs. After testing this I realized that this is still true so I attempted to make my own wait for all command but I'm having mass slow downs because the way I've coded it checks through all NPCs 0-300. Is there a simpler way to wait for all NPCs with less slowdown?

For the time being I've replaced all my "wait for all npcs" commands with "wait(1)" and this seems to be sufficient time to allow for all NPCs to reach their destinations. I fear that this method of coding will break depending on how many NPCs I have on the map though and could lead to further problems.
Last edited by sheamkennedy on Fri Feb 23, 2018 6:54 am, edited 1 time in total.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

'wait for all' wrote: if 'suspend npcs' is active, waits for all NPCs to stop walking
So, you want to wait for all NPCs but you don't want to use 'suspend npcs'? That's fair enough, if you want to do something like wait for all 'Chase' NPCs to reach the hero.

Looping through all 300 NPC references and checking whether they're moving won't cause a slowdown. Maybe the mistake you made was to loop through NPC IDs instead of NPC references, if you looped from 0 to 300 instead of from -1 to -300. That is a bit slower because for each NPC ID it needs to search for an NPC instance matching that ID. If you have 300 NPCs, that's roughly 300*300/2 = 45,000 steps. But that should definitely still not be enough to make the game run slower.

The best and most efficient way to loop through NPC instances is using the "next npc reference" command.

Edit:

After reading your other thread, I realise that what you want is this:

Code: Select all

resume npcs
wait(1)  # Let NPCs start moving
suspend npcs
wait for all  # Get the NPCs to stop
Note that if an NPC is set to Wander, it randomly waits a few ticks before starting to move. So given just one tick it has, IIRC, only a 1/4 chance of moving. You would want to increase the wait(1) to work around that.
Last edited by TMC on Fri Feb 23, 2018 7:17 am, edited 4 times in total.
User avatar
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Thanks this seems to be working.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
� C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Post Reply