Why am I getting this error message? Set NPC Obstruct (0,0)

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:

Why am I getting this error message? Set NPC Obstruct (0,0)

Post by sheamkennedy »

I have a script which is attempting to make all copies of a certain NPC non-obstructive. The code is as follows:

Code: Select all

#Make NPC 21 Non-obstructive
variable(copy)
for(copy, 0, 23) do(
  	set NPC obstructs (NPC reference (21, copy), false)
)


I am getting an error message saying:
setnpcobstructs:invalid NPC reference; no NPCs of ID 0 exist

When I enter the script debugger it says my script is trying to "set NPC obstruct (0, 0)." As far as I understand my code shouldn't be doing that. If I skip the error message the code also works as I had intended, just not sure where this error is coming from...
Last edited by sheamkennedy on Sat Mar 26, 2016 9:24 pm, edited 2 times 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
Soule X
Red Slime
Posts: 86
Joined: Wed Sep 19, 2012 4:18 pm
Location: Indianapolis

Post by Soule X »

It looks like it's pointing to an NPC that isn't there. Are you sure you have 24 instances of NPC 21?
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

As Soule X said. "NPC reference" returns 0/false if no such copy exists. Instead, you can write:

Code: Select all

variable(copy)
for(copy, 0, NPC copy count(21) -- 1) do(
     set NPC obstructs (NPC reference (21, copy), false)
)
or

Code: Select all

variable(copy)
for(copy, 0, 23) do(
     if (NPC reference (21, copy)) then (
          set NPC obstructs (NPC reference (21, copy), false)
     )
)
Last edited by TMC on Sun Mar 27, 2016 2:37 am, edited 1 time in total.
Post Reply