Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.
Moderators: marionline , SDHawk
sheamkennedy
Liquid Metal Slime
Posts: 1110 Joined: Mon Sep 16, 2013 9:29 pm
Location: Tama-shi, Tokyo, Japan
Contact:
Post
by sheamkennedy » Sat Mar 26, 2016 9:22 pm
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.
Soule X
Red Slime
Posts: 86 Joined: Wed Sep 19, 2012 4:18 pm
Location: Indianapolis
Post
by Soule X » Sun Mar 27, 2016 12:55 am
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 » Sun Mar 27, 2016 2:37 am
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.