Post new topic    
Liquid Metal Slime
Send private message
How can I suspend NPCs when each step is first called? 
 PostThu Feb 22, 2018 10:42 am
Send private message Reply with quote
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:

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:

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?
⊕ 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
Liquid Metal Slime
Send private message
 
 PostThu Feb 22, 2018 4:18 pm
Send private message Reply with quote
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:
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.
I can't write in cursive.
Liquid Metal Slime
Send private message
 
 PostFri Feb 23, 2018 12:31 am
Send private message Reply with quote
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
Metal King Slime
Send private message
 
 PostFri Feb 23, 2018 7:14 am
Send private message Reply with quote
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:
 While ( current map == current map ) do(
is equivalent to:
Code:
 while(true) do (

Probably yout meant to write:
Code:
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.
Liquid Metal Slime
Send private message
 
 PostFri Feb 23, 2018 8:01 am
Send private message Reply with quote
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
Display posts from previous: