Problem: NPC creation delayed when running script...

Make games! Discuss those games here.

Moderators: Bob the Hamster, 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:

Problem: NPC creation delayed when running script...

Post by sheamkennedy »

I'm having this weird problem and can't figure it out.

I have 2 scripts, each of which are run when you step on an NPC (NPC #12, and NPC #13).

On the map, NPC #12 is placed directly above NPC#13. Depending on which of these NPCs the character steps on, a slightly different script will be run.

Here's the scripts:

If you step on NPC #12:

Code: Select all

plotscript, sunkenA_AfterJumpAcrossLedgesNPC12, begin
  suspend player 
  suspend random enemies 
  suspend caterpillar 
  suspend NPCs 
  suspend box advance
  
  show text box (13)
  wait (34)
  set NPC direction (10, right)
  wait(4)
  show text box (14)
  wait(10)
  advance text box
  focus camera (31, 19, 10)
  walk NPC (10, right, 4)
  walk hero (me, right, 5)
  wait for hero (me)
  walk hero (me, down, 1)
  wait for hero (me)
  walk hero (me, right, 1)
  #wait for hero (me)
  wait for camera
  
  #The Guard's Patrol Sequence
  sunkenA_GuardKilledByJinso 
  
  #camera follows hero
  destroy NPC (12)
  destroy NPC (13)
  
  #resume player 
  #resume random enemies 
  #resume caterpillar 
  #resume NPCs 
end
If you step on NPC #13:

Code: Select all

plotscript, sunkenA_AfterJumpAcrossLedgesNPC13, begin
  suspend player 
  suspend random enemies 
  suspend caterpillar 
  suspend NPCs 
  suspend box advance
  
  set NPC direction (10, down)
  wait(4)
  
  show text box (13)
  wait (34)
  set NPC direction (10, right)
  wait(4)
  show text box (14)
  wait(10)
  advance text box
  focus camera (31, 19, 10)
  walk NPC (10, right, 4)
  walk hero (me, right, 2)
  wait for hero (me)
  walk hero (me, right, 3)
  wait for hero (me)
  walk hero (me, right, 1)
  #wait for hero (me)
  wait for camera
  
  #The Guard's Patrol Sequence
  sunkenA_GuardKilledByJinso
  
  #camera follows hero
  destroy NPC (12)
  destroy NPC (13)
  
  #resume player 
  #resume random enemies 
  #resume caterpillar 
  #resume NPCs 
end
And here's the embedded script which executes within both of these:

Code: Select all

 script, sunkenA_GuardKilledByJinso, begin
  #Guard Patrol Pattern
  create NPC (14, 33, 29, up)
  walk NPC (14, up, 8)
  wait for NPC (14)
  wait (20)
  walk NPC (14, right, 3)
  wait for NPC (14)
  wait (20)
  walk NPC (14, down, 1)
  wait for NPC (14)
  wait (20)
  walk NPC (14, left, 3)
  wait for NPC (14)
  wait (20)
  walk NPC (14, up, 1)
  wait for NPC (14)
  wait (20)
  walk NPC (14, right, 3)
end
What is supposed to happen is the character walks to a specific position, then we see a guard NPC who walks in a pattern via the sunkenA_GuardKilledByJinso script.

When stepping on NPC #12, the sunkenA_GuardKilledByJinso script executes perfectly. But when the character steps on NPC #13, the sunkenA_GuardKilledByJinso script seems to execute but the guard NPC (14) is not visible until about halfway through his pattern.

I don't understand what would cause this. I think I'm using all the right wait functions and as far as I can tell the NPC #12 & 13's scripts are basically the same asides from a few less steps in the latter.

I've gotta go to work now. If know one knows what I mean, I'll make a video later.
⊕ 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
sotrain515
Red Slime
Posts: 59
Joined: Wed Dec 26, 2012 3:23 pm

Post by sotrain515 »

Are there multiple guard NPCs on the map (NPC 14)?
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Here are a few things to check.

Right after the "create NPC (14, 33, 29, up)" add the following

Code: Select all

show value(NPC copy count(14))
This will tell you whether or not the NPC is being created correctly (and whether any other copies exist on the map)

Next try this:

Code: Select all

string sprintf(0, $1="X=%d y=%d", NPC X(14), NPC Y(14))
show string(0)
This will show where the NPC is located on the map. You could repeat this after each "wait for NPC (14) " to verify its movements.
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

I have no idea either. But you can press Ctrl+F11 to more easily show where all NPCs are, even if disabled.
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 troubleshooting tips, but after performing both methods of finding the problem I am still at a loss to understand what is occurring.

First I checked how many copies of the NPC existed for each case. In both cases my screen displayed "1."

Next I changed this portion of my script such that NPC #14's (x,y) is mapped out all throughout his walking pattern. The script now looks like this:

Code: Select all

script, sunkenA_GuardKilledByJinso, begin
  #Guard Patrol Pattern
  create NPC (14, 33, 29, up)
  string sprintf(0, $1="X=%d y=%d", NPC X(14), NPC Y(14)) 
  show string(0) 
  walk NPC (14, up, 8)
  wait for NPC (14)
  string sprintf(0, $1="X=%d y=%d", NPC X(14), NPC Y(14)) 
  show string(0) 
  wait (20)
  walk NPC (14, right, 3)
  wait for NPC (14)
  string sprintf(0, $1="X=%d y=%d", NPC X(14), NPC Y(14))
  show string(0) 
  wait (20)
  walk NPC (14, down, 1)
  wait for NPC (14)
  string sprintf(0, $1="X=%d y=%d", NPC X(14), NPC Y(14))
  show string(0) 
  wait (20)
  walk NPC (14, left, 3)
  wait for NPC (14)
  string sprintf(0, $1="X=%d y=%d", NPC X(14), NPC Y(14))
  show string(0) 
  wait (20)
  walk NPC (14, up, 1)
  wait for NPC (14)
  string sprintf(0, $1="X=%d y=%d", NPC X(14), NPC Y(14))
  show string(0) 
  wait (20)
  walk NPC (14, right, 3)
  string sprintf(0, $1="X=%d y=%d", NPC X(14), NPC Y(14))
  show string(0) 
end
The result can be seen in this video:

https://www.youtube.com/watch?v=fhPppitKHN0

Exhibit A: The first case of this script commences around the 0:33 in the video. At about 0:38 we see that NPC #14 has been created and his (x,y) position is being plotted. We then see him enter the screen and perform his pattern as the (x,y) is plotted throughout.

Exhibit B: Skip the video ahead to around 1:30 where the second case of the script commences. Note that the starting tile for the script is different and the script is thus slightly different to account for this as previously discussed. This time we see almost the same thing happen, but the NPC is not visible. The trouble shooting claims that the NPC is at these positions though and he suddenly appears towards the end of his pattern for no given reason.
⊕ 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
sheamkennedy
Liquid Metal Slime
Posts: 1110
Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:

Post by sheamkennedy »

Wow, I tend to do this a lot... I just resolved my own problem. The problem was me failing to use my "embiggen now" script after the "create NPC" script. Since the NPC was not embiggened, he took on the undrawn form of the walkabout sprite which corresponds to the hero #.

Still though I can't figure out why the NPC suddenly embiggens part way through the pattern like in the video since there was nothing like that in the script or in any script that would be running at that time... freaky.

Anyways the problem is solved and now I'll spend the rest of the night frustrated with myself for even putting in such an effort to make a video about it. Gah.
⊕ 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