How can I suspend NPCs when each step is first called?

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 can I suspend NPCs when each step is first called?

Post by sheamkennedy »

I am playing around with a rogue like idea. The enemy NPCs are only to move when I, the hero, moves. I have suspended their movement in the autorun script like so:

Code: Select all

plotscript, Map Auto Run 1, begin
  stopAllNPCs # This script uses "set NPC moves ()" to stop specified NPCs
  While ( current map == current map ) do(
    # For turn-based movement:
    if(hero is walking (0)) then(
      suspend player
      resumeAllNPCs # This script uses "set NPC moves ()" to resume specified NPCs
      wait # Must wait 1 tick before stopping NPCs
      stopAllNPCs # This script uses "set NPC moves ()" to stop specified NPCs
      wait for hero(me)
      resume player
    )  
  wait    
  )
end
This autorun worked great until I introduced an eachstep script. The eachstep script seems to get automatically called when the map is initialized. This means that all of my NPCs take a single step before they're suspended even though my hero does not physically take a step from his map start (x,y)

My each step looks like this:

Code: Select all

plotscript, eachstep 0, begin
  # Wait for everything to reach it's next position
    wait for all
  # Check spaces adjacent to hero
    checkAdjacent
end
Is there a way that I can modify the eachstep script so it does not get called when the map is initialized?
Last edited by sheamkennedy on Thu Feb 22, 2018 10:44 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
User avatar
kylekrack
Liquid Metal Slime
Posts: 1240
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

I had this issue. You could add a tag that's set true by the autorun and check it in your eachstep. The top of the eachstep script would then be

Code: Select all

script, eachstep, begin
    if(checktag(tag:number) == false) then(
        exit script
    )
end
Alternatively you could check for something, like a slice that only exists once the autorun has been called. That way you don't have to introduce anything new, like a tag.
My pronouns are they/them
Ps. I love my wife
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 for the solution, that'll work.
⊕ 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 »

The each-step script is indeed run automatically when you enter a map or start a new game, and it runs before the map autorun and new-game scripts. Which is weird. Kylekrack pointed this out to me.

This:

Code: Select all

 While ( current map == current map ) do( 
is equivalent to:

Code: Select all

 while(true) do (
Probably yout meant to write:

Code: Select all

variable (map)
map := current map
while (map == current map) do (
To make the script stop if the map changes.

Unfortunately if the new map has a map-autorun script, it'll start running before the old script gets a chance to notice the map change, and it'll suspend the old script. So if every map has a similar map autorun, the scripts will just pile up forever until the limit is reached (512 scripts/map changes). Unlikely to happen.
Last edited by TMC on Fri Feb 23, 2018 7:17 am, edited 1 time 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 »

Oh my mistake. I'll fix that up now.
⊕ 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