Scripting

From High Fidelity Documentation
Jump to: navigation, search

Getting started with Scripting in High Fidelity

High Fidelity lets you use Javascript both for attaching behaviors to in-world objects, as well as for running scripts on your client to do things like add UI elements or change what your hand controllers do. Much of the existing behavior of the client can be extended or over-written using scripts. Below is a list of things to know to get started:

Advanced and Developer menus: First, you need to go to 'Settings' and enable both Advanced and Developer menus so you can bring up the various menu options you will need.

Running Scripts Dialog: Edit->running scripts or Ctrl+J. You will see a dialog with a list of running client scripts. You can run a new script by loading them from URL or local disk using the buttons provided. At the bottom there is a filter that lets you search for some (hopefully) helpful scripts that we install with your client. For example, type 'stats' in the filter and expand developer->utilities->audio->stats.js and press 'load' to see a dialog with a bunch of detailed network stats on the audio pipeline and latency. To stop a script, press the 'X' button next to it.

Reloading scripts when editing: For a client script, you can click the reload button that is to the right of the script name in the running scripts dialog. For an entity script, you can either Edit->Reload All Scripts (Ctrl + R), or you can edit the entity and press the reload button next to the script URL in the properties dialog.

Editing Default Scripts: There are a bunch of default scripts that load together when you startup. To see those broken out so that you can individually turn then on or off as needed, Developer->Debug defaultScripts.js. You will then see all the scripts shown separately in the window and can start and stop or reload them. Sometimes this will get you in a bad state where none of your scripts are working. If this happens, press Ctrl+J to bring up running scripts, press 'Remove All' and then 'Load Defaults'

Choosing a script editor: You can use any editor you want, and task switch back and forth. We have a really basic editor at Edit->Script Editor, but it won't show up in the HMD. You probably won't like it, but it does show up in the client window. Build us one in the HMD and we will be ecstatic.

Debugging: To see error messages and text sent by your scripts, got to Developer->Script Log. This window is visible from within the HMD too. Inteface also has a main log screen, which you can access from Developer->Log or with Shift+Ctrl+L. This window is not visible in the HMD, but can be dragged outside the main interface window. This will let you minimally debug. We don't yet have a live debugger (you could build us one, which would be great).

Entity scripts run on all users: If you attach a script to an entity, everyone who sees that entity will run that script. So, for example, if you set a timer to do something (like move an entity a random amount) every second, and there are three people in your server that can see that entity, it is going to get moved three times a second. This is something that is powerful but can trip you up if you forget it. Entity scripts are run by everyone, not just you.

Add a local file as an entity script: If you are editing an entity and want to add a script to it, find the Script URL field in the entity properties panel, and then use "file:///c:/dev/myscript.js" to specify a local file versus a network URL. Bear in mind of course that if someone else comes to your server, they will not be able to see the script. To test with multiple people, you need to either deploy the script at a reachable URL, or upload the script to the ATP server on your server.

Editing in the HMD: Yeah it's a pain. Setup an editor in another window, save to file, then alt-Tab between windows. HMD's are still too low resolution to really edit code effectively, and of course you can't see the keyboard.