Skip to content

JavaScript

ThePix edited this page Sep 1, 2019 · 27 revisions

JavaScript has some important differences if you are used to ASL, the coding language for Quest 5.

ASL is a somewhat cut down language, and as it runs on top of the Quest player, you do not have access to everything, so is a little limited. One of the biggest limitations is that you cannot pass parameters to a script or return a value (well, you can, using delegates, but the editor does not support it, so it is a bad idea).

JavaScript is a fully-fledge programming language, and as everything is written in JavaScript, you have access to everything. When you convert from ASL to JavaScript, you will tend to encounter the downside of JavaScript, because your existing code will not be designed to make use of the features only in JavaScript.

Declare variables

In JavaScript you have to declare a variable before you use. If it is going to change, use let, if it is not going to change, useconst.

const height = obj.getHeight()  // height cannot change
let n                           // n can change
n = height + 4                  // so now n changes
const list = []                 // list cannot change...
list.push(n)                    // but its contents can

If you are unsure if a variable will change, use let. There is also an older keyword, var, which is much like let.

End a line with a semi-colon... or not

I put a semi-colon at the end of each line, but they are optional, so please yourself.

Testing equality and inequality

I you want to compare two variables to see if they are equal, in ASL you use an equals sign. For not equal, use less than then greater than:

if (height = 12) {

if (height <> 12) {

Most modern programming languages use two equals signs to differentiate from when you are assigning a value, and an exclamation mark and equals sign for "not equals". JavaScript is the same, but will first try to "coerce" the types, which can give some unexpected behaviour. It is safer to use three equals signed:

if (height === 12) {

if (height !== 12) {

For Boolean operations:

and     &&
or      ||
not     !

Strings

As in ASL, a string can be denoted by double quotes, but you can also use singles - as long as they are the same at both ends. This allows you to include quotes in your string.

s = "Strings with double quotes are cool, aren't they?"
s = '"No!" she said emphatically.'

Dictionaries and lists

Loops

Tutorial

QuestJS Basics

The Text Processor

Commands

Templates for Items

See also:

Handing NPCs

The User Experience (UI)

The main screen

The Side Panes

Multi-media (sounds, images, maps, etc.)

Dialogue boxes

Other Elements

Role-playing Games

Web Basics

How-to

Time

Items

Locations

Exits

Meta

Meta: About The Whole Game

Releasing Your Game

Reference

Clone this wiki locally