Well for the most part because it is server-side you don't have to do the..
SwitchDB = findnpc("SwitchDB");
because the NPC is accessible via it's name without having to declare a global variable.
Following KISS theory...
SwitchDB
PHP Code:
// Empty Script
// Just using it to hold variables for now.
Switch
PHP Code:
function onCreated() {
this.doorid = "door_1";
this.image = "block.png";
echo(this.doorid @ "'s switch has been created!");
}
function onPlayerTouchsMe() {
echo(player.account @ " touched the switch for door " @ this.doorid);
SwitchDB.door.(@this.switchid).trigger("DoorOpened", player.account);
}
Door
PHP Code:
function onCreated() {
this.doorid = "door_1";
this.image = "door.png";
SwitchDB.door.(@this.doorid) = this;
echo(this.doorid @ "'s door has been created!");
}
function onDoorOpened(acct) {
echo(this.doorid @ " has been opened by " @ acct @ "!");
hide();
sleep(3);
show();
}
From there we can work off the base and create the proper SwitchDB and classes that we require.
In my own "switch" system I store the main controller object (i.e: the door) and it's respective array of switches, and send a trigger to the main controller when a switch is updated (pressed on and off for instance) and the controller loops through the switches and performs the necessary logic (all switches are pressed down) and acts accordingly.