OSCII-bot code reference

Generated by OSCII-bot v0.3

Scripts use lines beginning with @ to specify various parameters:Special variables: The code for OSCII-bot is written in a simple language (called EEL2), which has many similarities to C. Code is written in one or more of the code sections listed above. Some basic features of this language are:

Operator reference

Listed from highest precedence to lowest (but one should use parentheses whenever there is doubt!):

Some key notes about the above, especially for C programmers:


Strings can be specified as literals using quotes, such as "This is a test string". Much of the syntax mirrors that of C: you must escape quotes with backslashes to put them in strings ("He said \"hello, world\" to me"), multiple literal strings will be automatically concatenated by the compiler. Unlike C, quotes can span multiple lines. There is a soft limit on the size of each string: attempts to grow a string past about 16KB will result in the string not being modified.

Strings are always refered to by a number, so one can reference a string using a normal JS variable:
    x = "hello world";
Literal strings are mutable in OSCII-bot, and you can also have other named strings:

Function List

while     freembuf     strcpy     time_precise     ftell     gfx_setfont    
loop     memcpy     strcat     eval     feof     gfx_getfont    
sin     memset     strcmp     tcp_listen     fflush     gfx_printf    
cos     stack_push     stricmp     tcp_listen_end     gfx_init     gfx_blurto    
tan     stack_pop     strncmp     tcp_connect     gfx_quit     gfx_blit    
sqrt     stack_peek     strnicmp     tcp_send     gfx_aaaaa     gfx_blit    
log     stack_exch     strncpy     tcp_recv     gfx_getchar     gfx_blitext    
log10     rand     strncat     tcp_set_block     gfx_lineto     gfx_getimgdim    
asin     midisend     strcpy_from     tcp_close     gfx_line     gfx_setimgdim    
acos     oscsend     strcpy_substr     fopen     gfx_rectto     gfx_loadimg    
atan     oscmatch     str_getchar     fclose     gfx_rect     gfx_gradrect    
atan2     oscparm     str_setchar     fread     gfx_setpixel     gfx_muladdrect    
exp     printf     str_setlen     fgets     gfx_getpixel     gfx_deltablit    
abs     sprintf     str_delsub     fgetc     gfx_drawnumber     gfx_transformblit    
sqr     matchi     str_insert     fwrite     gfx_drawchar     gfx_circle    
min     match     sleep     fprintf     gfx_drawstr     gfx_roundrect    
max     strlen     time     fseek     gfx_measurestr     gfx_arc    
sign     strcpy     time_precise     ftell    


Executes expression until expression evaluates to zero, or until 1048576iterations occur. An alternate and more useful syntax is while (expression) ( statements ), which evaluates statements after every non-zero evaluation of expression.


Evaluates count once, and then executes expression count, but not more than 1048576, times.


Returns the sine of the angle specified (specified in radians -- to convert from degrees to radians, multiply by $pi/180, or 0.017453).


Returns the cosine of the angle specified (specified in radians).


Returns the tangent of the angle specified (specified in radians).


Returns the square root of the parameter. If the parameter is negative, the return value is undefined.


Returns the natural logarithm (base e) of the parameter. If the value is not greater than 0, the return value is undefined.


Returns the base-10 logarithm of the parameter. If the value is not greater than 0, the return value is undefined.


Returns the arc sine of the value specified (return value is in radians). If the parameter is not between -1.0 and 1.0 inclusive, the return value is undefined.


Returns the arc cosine of the value specified (return value is in radians). If the parameter is not between -1.0 and 1.0 inclusive, the return value is undefined.


Returns the arc tangent of the value specified (return value is in radians). If the parameter is not between -1.0 and 1.0 inclusive, the return value is undefined.


Returns the arc tangent of the numerator divided by the denominator, allowing the denominator to be 0, and using their signs to produce a more meaningful result.


Returns the number e ($e, approximately 2.718) raised to the parameter-th power. This function is significantly faster than pow() or the ^ operator.


Returns the absolute value of the parameter.


Returns the square of the parameter (similar to value*value, but only evaluating value once).


Returns (by reference) the minimum value of the two parameters. Since min() returns by reference, expressions such as min(x,y) = 5 are possible.


Returns (by reference) the maximum value of the two parameters. Since max() returns by reference, expressions such as max(x,y) = 5 are possible.


Returns 1.0 if the parameter is greater than 0, -1.0 if the parameter is less than 0, or 0 if the parameter is 0.


Returns the value rounded to the next lowest integer (floor(3.9)==3, floor(-3.1)==-4).


Returns the value rounded to the next highest integer (ceil(3.1)==4, ceil(-3.9)==-3).


Returns a fast inverse square root (1/sqrt(x)) approximation of the parameter.


Hints the runtime that memory above the address specified may no longer be used. The runtime may, at its leisure, choose to lose the contents of memory above the address specified.


Copies length items of memory from src to dest. Regions are permitted to overlap.


Sets length items of memory at offset to value.


Pushes value onto the user stack, returns a reference to the parameter.


Pops a value from the user stack into value, or into a temporary buffer if value is not specified, and returns a reference to where the stack was popped. Note that no checking is done to determine if the stack is empty, and as such stack_pop() will never fail.


Returns a reference to the item on the top of the stack (if index is 0), or to the Nth item on the stack if index is greater than 0.


Exchanges a value with the top of the stack, and returns a reference to the parameter (with the new value).


Returns a psuedorandom real number between 0 and the parameter, inclusive. If the parameter is omitted or less than 1.0, 1.0 is used as a maximum instead.


Sends a MIDI event (specified by variables msg1,msg2,msg3) to the device specified by device_index.

device_index can be -100 to send to all outputs opened by application, -1 to send to all outputs opened by script.


Sends an OSC event (specified by "string" and one or more parameters specifying values) to device specified by device_index.

device_index can be -100 to send to all outputs opened by application, -1 to send to all outputs opened by script.

"string" is OSC message, and can have a prefix specifying type and count of values.

Additional parameters (after values) will be used as parameters to any format specifiers in "string".

Prefixes are one or more characters of 'f' (float), 'i' (integer), 'b' (bool), 's' (string), which specify an OSC value of that type.


Matches the current OSC event against "string" (see match()), and puts any matched specifiers (%s, %d, etc) into parameters specified (or fmt0..fmtX if not specified).

oscmatch() is the equivalent of match("string",oscstr)


Gets the parameter value for the current OSC message.

If type is specified, it will be set to the type of the parameter ('f', 's', etc).

If #string is specified and type is 's', #string will be set to the OSC parameter string.

printf("format"[, ...])

Output formatted string to system-specific destination, see sprintf() for more information

sprintf(#dest,"format"[, ...])

Formats a string and stores it in #dest. Format specifiers begin with %, and may include:
Many standard C printf() modifiers can be used, including:
Values for format specifiers can be specified as additional parameters to sprintf, or within {} in the format specifier (such as %{varname}d, in that case a global variable is always used).

matchi("needle","haystack"[, ...])

Case-insensitive version of match().

match("needle","haystack"[, ...])

Searches for the first parameter in the second parameter, using a simplified regular expression syntax.
You can also use format specifiers to match certain types of data, and optionally put that into a variable:
See also sprintf() for other notes, including specifying direct variable references via {}.


Returns the length of the string passed as a parameter


Copies the contents of srcstr to #str, and returns #str


Appends srcstr to #str, and returns #str


Compares strings, returning 0 if equal


Compares strings ignoring case, returning 0 if equal


Compares strings giving up after maxlen characters, returning 0 if equal


Compares strings giving up after maxlen characters, ignoring case, returning 0 if equal


Copies srcstr to #str, stopping after maxlen characters. Returns #str.


Appends srcstr to #str, stopping after maxlen characters of srcstr. Returns #str.


Copies srcstr to #str, but starts reading srcstr at offset offset


PHP-style (start at offs, offs<0 means from end, ml for maxlen, ml<0 = reduce length by this amt)


Returns the data at byte-offset offset of str. If offset is negative, position is relative to end of string.type defaults to signed char, but can be specified to read raw binary data in other formats (note the single quotes, these are single/multi-byte characters):


Sets value at offset offset, type optional. offset may be negative to refer to offset relative to end of string, or between 0 and length, inclusive, and if set to length it will lengthen string. see str_getchar() for more information on types.


Sets length of #str (if increasing, will be space-padded), and returns #str.


Deletes len characters at offset pos from #str, and returns #str.


Inserts srcstr into #str at offset pos. Returns #str


Yields the CPU for the millisecond count specified, calling Sleep() on Windows or usleep() on other platforms.


Sets the parameter (or a temporary buffer if omitted) to the number of seconds since January 1, 1970, and returns a reference to that value. The granularity of the value returned is 1 second.


Sets the parameter (or a temporary buffer if omitted) to a system-local timestamp in seconds, and returns a reference to that value. The granularity of the value returned is system defined (but generally significantly smaller than one second).


Executes code passed in. Code can use functions, but functions created in code can't be used elsewhere.


Listens on port specified. Returns less than 0 if could not listen, 0 if no new connection available, or greater than 0 (as a TCP connection ID) if a new connection was made. If a connection made and #ip_out specified, it will be set to the remote IP. interface can be empty for all interfaces, otherwise an interface IP as a string.


Ends listening on port specified.


Create a new TCP connection to address:port. If block is specified and 0, connection will be made nonblocking. Returns TCP connection ID greater than 0 on success.


Sends a string to connection. Returns -1 on error, 0 if connection is non-blocking and would block, otherwise returns length sent. If len is specified and not less than 1, only the first len bytes of the string parameter will be sent.


Receives data from a connection to #str. If maxlen is specified, no more than maxlen bytes will be received. If non-blocking, 0 will be returned if would block. Returns less than 0 if error.


Sets whether a connection blocks.


Closes a TCP connection created by tcp_listen() or tcp_connect().


Opens a file "fn" with mode "mode". For read, use "r" or "rb", write "w" or "wb". Returns a positive integer on success.


Closes a file previously opened with fopen().


Reads from file fp into #str, up to length bytes. Returns actual length read, or negative if error.


Reads a line from file fp into #str. Returns length of #str read.


Reads a character from file fp, returns -1 if EOF.


Writes up to len characters of #str to file fp. If len is less than 1, the full contents of #str will be written. Returns the number of bytes written to file.


Formats a string and writes it to file fp. For more information on format specifiers, see sprintf(). Returns bytes written to file.


Seeks file fp, offset bytes from whence reference. Whence negative specifies start of file, positive whence specifies end of file, and zero whence specifies current file position.


Retunrs the current file position.


Returns nonzero if the file fp is at the end of file.


If file fp is open for writing, flushes out any buffered data to disk.


Initializes the graphics window with title name. Suggested width and height can be specified.

Once the graphics window is open, gfx_update() should be called periodically.


Closes the graphics window.


The following global variables are special and will be used by the graphics system:


If char is 0 or omitted, returns a character from the keyboard queue, or 0 if no character is available, or -1 if the graphics window is not open. If char is specified and nonzero, that character's status will be checked, and the function will return greater than 0 if it is pressed.

Common values are standard ASCII, such as 'a', 'A', '=' and '1', but for many keys multi-byte values are used, including 'home', 'up', 'down', 'left', 'rght', 'f1'.. 'f12', 'pgup', 'pgdn', 'ins', and 'del'.

Modified and special keys can also be returned, including:


Draws a line from gfx_x,gfx_y to x,y. if aa is 0.5 or greater, then antialiasing is used. Updates gfx_x and gfx_y to x,y.


Draws a line from x,y to x2,y2, and if aa is not specified or 0.5 or greater, it will be antialiased.


Fills a rectangle from gfx_x,gfx_y to x,y. Updates gfx_x,gfx_y to x,y.


Fills a rectngle at x,y, w,h pixels in dimension.


Writes a pixel of r,g,b to gfx_x,gfx_y.


Gets the value of the pixel at gfx_x,gfx_y into r,g,b.


Draws the number n with ndigits of precision to gfx_x, gfx_y, and updates gfx_x to the right side of the drawing. The text height is gfx_texth.


Draws the character (can be a numeric ASCII code as well), to gfx_x, gfx_y, and moves gfx_x over by the size of the character.


Draws a string at gfx_x, gfx_y, and updates gfx_x/gfx_y so that subsequent draws will occur in a similar place.


Measures the drawing dimensions of a string with the current font (as set by gfx_setfont).

gfx_setfont(idx[,"fontface", sz, flags])

Can select a font and optionally configure it. idx=0 for default bitmapped font, no configuration is possible for this font. idx=1..16 for a configurable font, specify fontface such as "Arial", sz of 8-100, and optionally specify flags, which is a multibyte character, which can include 'i' for italics, 'u' for underline, or 'b' for bold. These flags may or may not be supported depending on the font and OS. After calling gfx_setfont(), gfx_texth may be updated to reflect the new average line height.


Returns current font index.

gfx_printf("format"[, ...])

Formats and draws a string at gfx_x, gfx_y, and updates gfx_x/gfx_y accordingly (the latter only if the formatted string contains newline). For more information on format strings, see sprintf()


Blurs the region of the screen between gfx_x,gfx_y and x,y, and updates gfx_x,gfx_y to x,y.


If three parameters are specified, copies the entirity of the source bitmap to gfx_x,gfx_y using current opacity and copy mode (set with gfx_a, gfx_mode). You can specify scale (1.0 is unscaled) and rotation (0.0 is not rotated, angles are in radians).
For the "source" parameter specify -1 to use the main framebuffer as source, or an image index (see gfx_loadimg()).

gfx_blit(source, scale, rotation[, srcx, srcy, srcw, srch, destx, desty, destw, desth, rotxoffs, rotyoffs])

srcx/srcy/srcw/srch specify the source rectangle (if omitted srcw/srch default to image size), destx/desty/destw/desth specify dest rectangle (if not specified, these will default to reasonable defaults -- destw/desth default to srcw/srch * scale).


Deprecated, use gfx_blit instead.


Retreives the dimensions of image (representing a filename: index number) into w and h. Sets these values to 0 if an image failed loading (or if the filename index is invalid).


Resize image referenced by index 0..127, width and height must be 0-2048. The contents of the image will be undefined after the resize.


Load image from filename into slot 0..127 specified by image. Returns the image index if success, otherwise -1 if failure. The image will be resized to the dimensions of the image file.

gfx_gradrect(x,y,w,h, r,g,b,a[, drdx, dgdx, dbdx, dadx, drdy, dgdy, dbdy, dady])

Fills a gradient rectangle with the color and alpha specified. drdx-dadx reflect the adjustment (per-pixel) applied for each pixel moved to the right, drdy-dady are the adjustment applied for each pixel moved toward the bottom. Normally drdx=adjustamount/w, drdy=adjustamount/h, etc.


Multiplies each pixel by mul_* and adds add_*, and updates in-place. Useful for changing brightness/contrast, or other effects.


Blits from srcimg(srcx,srcy,srcw,srch) to destination (destx,desty,destw,desth). Source texture coordinates are s/t, dsdx represents the change in s coordinate for each x pixel, dtdy represents the change in t coordinate for each y pixel, etc. dsdxdy represents the change in dsdx for each line.


Blits to destination at (destx,desty), size (destw,desth). div_w and div_h should be 2..64, and table should point to a table of 2*div_w*div_h values (this table must not cross a 65536 item boundary). Each pair in the table represents a S,T coordinate in the source image, and the table is treated as a left-right, top-bottom list of texture coordinates, which will then be rendered to the destination.


Draws a circle, optionally filling/antialiasing.


Draws a rectangle with rounded corners.


Draws an arc of the circle centered at x,y, with ang1/ang2 being specified in radians.