Scripter2 Help Page

So you're wanting to give Scripter2 a test run.. Well, you've came to the right place. The Scripter2 demo application is at

There are a few limitations to keep in mind for the demo application

  1. Scripts can be no longer than 1000 bytes long
  2. Scripts are sandboxed completely(so far). return is the only way to get data out of your scripts right now
  3. Scripts can take no longer than 5 seconds to execute
  4. Script results will be trimmed if they are larger than 2000 bytes
  5. Floating point operations are unimplemented so far
  6. && and || logical and/or is not supported yet (nor is truely logical !)

With that in mind, continue...

We'll start of course with a hello world application:

return "Hello World!";

Now I'll try to cover a few different topics:

Variable Declarations

Although variables can be created without prior declaration, it is not how I recommend doing things.

There are two different variable scopes available. Local and Global.

var l; //local variable
global var g; //global variables

Global variables can be accessed from any scope, including inside functions(without passing it in as an argument). Local variables are local to their scope. Scopes are "created" via {} or by function calls. For example:

var bar="baz";
  var foo="biz";
bar=foo; //bar is now `undefined` 
var f=function(){
  var fizz="123";
bar=fizz; //bar is now `undefined`


Tables are the cure-all to all data structures you'll use in Scripter2. Tables can implement lists, hashes, dictionaries, arrays, classes, structures, and anything else you can think of.

var table=[]; //an empty table
table=[1,2,3] //a 0 indexed array containing 1, 2, 3
table=["foo" => "bar"];
//for string keys, short cutting similar to javascript is allowed

Tables can be added on to without any special operators as well.

var table=[];"bar";

There are also several built in functions for transversing and getting information about tables.

var table=[1, 2, 3];
var keys=keylist(table); //A table is returned like [0 => 0, 1 => 1, 2 => 2]
var count=keycount(table); //returns 3

There is also a foreach operation as well:

var table=["foo" = > "bar", "biz" => "baz"];
foreach(value in table){
  //value will be "bar" and then "baz"
foreach(key => value in table){
  //key will be "foo" and then "biz"
  //value will be "bar" and then "baz"

Private Table Keys

Any key put in a table that is prefixed with _ will be not included in the keylist nor keycount, and therefore will not used in foreach either.

This is to allow for "private" variables. There are some more plans(such as operator overloading) up my sleeve, but so far these are not implemented.

Note private variables can still be modified from anywhere though:

var table=["_foo" => "bar"];

These private variables will be much more useful as the facilities for duck-typing are fleshed out further.

Built in keywords

We already discussed the foreach keyword. There is also if and while which behaves as you would expect:

var i=0;
  return "all is not well";
  return "all is well";

There are also some built in functions, such as keycount, keylist, and isdefined. There are also some built in value keywords. These are null, nil, true, false, and undefined

Is Defined

The isdefined builtin function will test if a variable is equal to undefined. Due to operator and casting issues, it's not possible to do this with an if statement.

isdefined can return some false positives, depending on how you look at it. For instance, if you have a variable like this: var v=undefined; then isdefined(v) though being "declared" will return true. I believe that this is proper behavior and I'm don't really see much of a better way to do it.

isdefined can also be used on tables. For instance,

var table=[];

Type casting

Type casting is a bit odd right now(hopefully cleaned up as we get closer to 1.0), I'll just warn you.

There is implicit type casting done on nearly every operation. The type to the right of the operation is cast to the type left of the operation.

Some examples:

var s="0123";
var i=5;

There is also support for explicit type casting using the as operator.

Some examples:

var s="0123";
var i=5;
assert((i as string)+"123" == "5123");
assert((s as integer)+5 == 128);

You can also test for a type using the is operator.

assert([] is table);
assert 123 is integer);
assert("foo" is string);
assert(function(){} is function);


Function are treated basically the same as variables and are first class. Lambda support is not yet included however.

Declaring a function is quite easy and looks exactly like Javascript:

var f=function(x){
    return x+1;

Functions can also be used in tables to produce things that look oddly similar to classes

var foo=[];
  return "bar";

Functions, though they are first class and can be passed around with ease, have next to no operations that can be performed on them. They can not be cast to any other type and do not support any operators such as ==

Operator List

Here is a full list of operators:

x++; //postfix increment
x--; //postfix decrement
++x; //prefix increment
--x; //prefix decrement
x*y; //binary multiplication
x/y; //binary division
x%y; //binary modulo
x+y; //binary addition
x-y; //binary subtraction
-x; //unary minus
+x; //unary plus
!x; //logical not
~x; //bitwise not
x&y; //bitwise and
x|y; //bitwise or
x^y; //bitwise xor
x<<y; //shift left
x>>y; //shift right
x=y; //assignment
x==y; //equals
x!=y; //not equal
x as Y; //typecast
x is y; //type comparison
x[y]; //subscript
x.y; //subscript shortcut


There are two different quote characters allowed.

"foo"; //both the same

There is nothing special between them and is just a matter of personal preference.

There are also some escape codes:

  1. \n newline
  2. \r linefeed
  3. \ \
  4. \' '
  5. \" "


Hopefully that explains enough for right now. If you find anything that causes, say a NullReferenceException or other error that isn't a Engine Error, I'd really appreciate a comment down below with the code that caused it.

Tags: scripter2
Posted: 6/29/2012 3:05:55 AM


Posting comments is currently disabled(probably due to spam)