A very clever wolf has persistently been asking me to implement scripting.
It is one of those features I’ve always planned to add eventually. And maybe now is a good time.
But it is a big piece that I need your help with on how to structure it and limit it.
@farcaller has already started helping me with ideas in this post: Simple scripting implementation idea
To limit the scope a bit, my first aim is this:
To be able to implement the Switches found at the Foxhole
In short; to allow a character to use a “switch” in one room, that effects other rooms. For more details, go to Foxhole and try to figure things out!
The scope means, I will not focus on exit events, allowing for making lockable exits, or global functionality as in farcaller’s suggestion to help create bankers. For now, let’s focus on room scripts only.
Requirements
It should be possible to, in a room, to add commands such as turn on switch
and turn off switch
, which can be used to:
- output a descriptive message in current room or other rooms
- change the settings (eg. profile) of the current room or other rooms
It should exist a way to list room-specific commands.
These requirements are just for this first test-implementation. More functionality will be added later.
Custom command registrations
Rooms scripts should be able to add and remove custom commands. The commands should be described with some json structure. With pseudo-js code, it could look like this:
room.addCommand({
cmd: "useSwitch",
steps: [
"turn",
{ type: "select", options: [ "on", "off" ] },
"switch",
],
});
When used, a command event will be triggered on the script.
In a similar way, room scripts may remove commands.
Adding/removing commands may be done live.
Built in commands have a higher priority than custom commands. So a room may not override the built-in say
command.
Room events
Apart from custom commands, room scripts should also be able to listen to other events such as charEnter, charLeave, charWakeup, and charSleep.
Room scripts MAY listen to communication events (whisper, say, pose, ooc, describe), but in such a case, the characters in the room should have an indicator showing that they are being listened to/recorded. This is in order to ensure integrity, and to avoid a false sense of privacy when scripts are listening.
Centralized or decentralized scripts
Here is one of my big questions regarding scripts. I see two different approaches:
-
Centralized scripts - Allow creation of a single script that may be able to control multiple rooms. For such a solution, a single script can add a switch in one room, and edit another room when the switch is used. But for this to work, a script must have access permission for the different rooms it may control.
-
Decentralized scripts - Alternatively, a room has a script. Only the owner (or a builder) may add a script to a room. For scripts to work across multiple rooms, scripts should have ways of sending messages to other scripts. It is up to the receiving script if it acts on that message. For such a solution, the room with the switch will have one script that sends a message to the target-room’s script to tell it to change the profile.
The decentralized approach be more work to manage. But I think it would simplify the permission structure, as “permission” is just based on whether a room’s script cares about messages from others.
API vs server-side VM
Where should scripts run?
For Centralized scripts, an API approach might be simplest. This means that scripts can be written in any language and be running on third party computers. Very much like bot-scripts. For such scripts, we could create JWT access tokens which is used by the script when connecting to the API. The token would tell which rooms/etc. the script has access to, and the script would be allow to subscribe to any/all of those rooms.
For Decentralized scripts, it would probably be easier to run them in some LUA VMs on the server. This means you would have to upload scripts (or have an in-game editor?), and have a harder time debugging a more complex system. But it would also lower the risk of having rooms stop functioning because of some external script being disconnected. And you don’t actually have to have a script server running all the time.
Okay… Those are some of my thoughts. I am a bit sleep now,
Please, help me think!