You also should make the setValue() function public in order for other npcs to be able to call it.
EDIT:
Here is probably what you are looking for:
NPC 1
PHP Code:
function onCreated() {
core = this;
}
public function setValue(oldVal, newVal)
(@ oldVal) = newVal;
NPC 2
PHP Code:
function onCreated() {
this.on = true;
core.setValue("this.on", (this.on = !this.on));
echo(this.on);
}
I know I changed it quiet a bit but it is sort of hard to see exactly what you want, sorry.
SECOND EDIT:
On second thought, that won't work either as "this.on" will be using the first NPC as "this" (in essence it would be the same as doing "core.setValue("core.on", (this.on = !this.on));")