CMYKilluminatiNetwork logo

Jump to:

BooBoo Core Functionality

The following describe the core functions of BooBoo. All of this can be used from the CLI version as well as the game engine.

Sections:

Core Functions

number

	declare a number or numbers
	e.g. number x y z

string

	declare a string or strings
	e.g. string s1 s2

vector

	declare a vector or vectors
	e.g. vector x

map

	declare a map or maps
	e.g. map m

pointer

	declare a pointer or pointers
	e.g. pointer p1 p2

reset

	load a different BooBoo script
	e.g. reset "next_slide.boo"

exit

	Exit the app with a return code to the environment
	e.g. exit 0

return

	Return a value from a function
	e.g. return 1
	or just return if the function doesn't return a value

include

	Include a BooBoo file at this point in the code
	e.g. include "my_functions.inc"

:

	Define a label
	e.g. :jump_here

;

	Define a comment
	e.g. = x 1 ; assign 1 to x

""

	a string
	e.g. = name "Pelvis Johnson"

function

	define a function
	References can be defined by prefixing a parameter name by a tilde (~)
	e.g. function foo param1 param2 ~param3 { ... }

typeof

	Returns a string respresentation of the type of the second parameter
	e.g. typeof type_string my_var

()

	an expression
	e.g. (+ x (* y (* z w 2))) in C would be x+(y*(z*w*2))
	Supported operators are: + - * / % && || > < >= <= == != | ^ & << >>
	The boolean operators return 1 or 0
	Your own functions can be supplied as operators

[]

	Vector/map indexing operator
	e.g. = x [v [m "key"]] in C++ would be x = v[m["key"]]
	Can be used anywhere a variable is expected.
	You can use multiple indexes
	e.g. [v 3 2 1 0] is like v[3][2][1][0] in C.

#

	Start a hexadecimal number
	e.g. #FF is equivalent to 255

~

	A reference. Function parameters preceded by a ~ can be modified
	by a function
	e.g. function foo a b ~c d ~e { ... } ; c and e can be modified

address

	Take the address of a variable into a pointer
	e.g. address my_pointer my_var

`

	Dereference operator. This is used to get/set the value pointed
	to by a pointer
	e.g. address p some_num
	e.g. = `p 10 ; some_num is now 10

Flow Control

goto

	jump to a label
	e.g. goto next_loop

?

	Comparison
	e.g. ? x 1
	You can also evaluate an expression
	? 1 (&& (> a b) (< x y)) je true jne false

je

	Jumps like this one are based on the last comparison. If it was equal,
	this will jump, if not, it won't
	e.g. je process_x_equals_1

jne

	Jump if not equal
	e.g. jne process_x_not_1

jl

	Jump if less
	e.g. jl my_label

jle

	Jump if less or equal
	e.g. jle my_label

jg

	Jump if greater
	e.g. jg my_label

jge

	Jump if greater or equal
	e.g. jge my_label

call

	Call a function that doesn't return anything
	e.g. call my_func param1 param2 param2

call_result

	Call a function that returns a value
	e.g. call_result result my_func param1 param2

if

	compare and jump
	e.g. if (expr1) the_if (expr2) elseif1 (expr3) elseif2 the_else
		; expr1 true code
	:the_if
		; expr2 true code
	:elseif1
		; expr3 true code
	:elseif2
		; else code
	:the_else

	the_if elseif1 elseif2 and the_else are labels that are the bottom of
	their code blocks. The else block is optional. Labels need to be in
	order of appearance in the if statement or behaviour is undefined.

for

	A for loop
	e.g. for i start (expression) increment end_label
		; your loop code here
	:end_label
	i is initialised to "start" then gets incremented
	by increment each loop until expression returns
	FALSE.

Arithmetic

=

	assign
	e.g. = x 1

+

	add
	e.g. + x 1
	You can supply more than 1 parameter at the end
	e.g. + x 10 foo bar 74 ; add all 4 to x

-

	subtract
	e.g. - x 1
	You can supply more than 1 parameter at the end

*

	multiply
	e.g. * x 2
	You can supply more than 1 parameter at the end

/

	divide
	e.g. / x 2
	You can supply more than 1 parameter at the end

%

	integer modulus
	e.g. % index count

String Functions

string_format

	format strings with replacements
	e.g. string_format dest "I'm % years old" age
	printf-equivalent formating options are available with %(...) for
	example %(3.16g)

string_char_at

	Get the value of character at index in a string
	This function is UTF8 compliant
	e.g. string_char_at dest str index

string_length

	Get the length of a string
	This function is UTF8 compliant
	e.g. string_length dest str

string_from_number

	Turns the ascii value into a one character length string
	This function is UTF8 compliant
	e.g. string_from_number str 97 ; creates "a"

string_substr

	Create a substring of a string
	e.g. string_substr s start end
	End is optional, if not specified it will cut from start till the
	end of the string.
	This is UTF8 compliant

string_uppercase

	Make a string uppercase
	e.g. string_uppercase s

string_lowercase

	Make a string lowercase
	e.g. string_lowercase s

string_trim

	Trim leading and trailing whitespace from a string
	e.g. string_trim s

string_replace

	regex replacement
	e.g. string_replace str regex replacement

string_match

	Extract sub-strings from a string
	e.g. string_match out_vector str regex

string_matches

	Check if a string matches a regex
	e.g. string_matches yesno str regex

Math Functions

fmod

	floating point modulus
	e.g. fmod x 1.5

sin

	trigonometry functions
	e.g. sin n

cos

	trigonometry functions
	e.g. cos n

tan

	trigonometry functions
	e.g. tan n

asin

	trigonometry functions
	e.g. asin n

acos

	trigonometry functions
	e.g. acos n

atan

	trigonometry functions
	e.g. atan n

atan2

	trigonometry functions
	e.g. atan2 y x

abs

	absolute value
	e.g. abs value

pow

	exponentiation
	e.g. pow x 2

sqrt

	square root
	e.g. sqrt x

hypot

	Calculate hypotenuse of a and b
	e.g. hypot a b

floor

	Drop the fractional part of a number
	e.g. floor x

ceil

	Round to the next highest integer
	e.g. ceil x

neg

	Invert the sign of a number
	e.g. neg x

sign

	Returns the sign of a number
	e.g. sign x

exp

	Calculate the value of e
	e.g. exp x

log

	Logarithm function
	e.g. log x

log10

	Base 10 logarithm
	e.g. log10 x

min

	Get the minimum number in a list of values
	e.g. min result a b c d e f g

max

	Get the max number in a list of values
	e.g. max result a b

Vector and matrix math

	Some vector and matrix math is available through expression
	operators. Supported are: mul, identity, scale, rotate,
	translate, length, dot, angle, cross, normalize, add, sub,
	inverse, transpose
	Most of these behave as you'd expect. identity takes 1 argument,
	the size of the matrix. scale, rotate and translate produce
	transformation matrices to be multiplied by another matrix
	(scale and translate take 3 parameters, rotate takes 4.)

Vector Functions

vector_add

	push a value onto a vector (must be created e.g. vector v)
	e.g. vector_add v 0

vector_size

	get the number of elements in a vector
	e.g. vector_size vec size

vector_set

	set an element in a vector
	e.g. vector_set vec index value
	Note: you can use multiple indices if you know you have a
	multidimensional vector. BooBoo will dig down into as many vectors as
	you specify indices for (followed by the value you're setting it to)

vector_insert

	insert a value in any position in a vector
	e.g. vector_insert v index value

vector_get

	get the value at index in vector
	e.g. vector_get v output index
	Note: you can use multiple indices if you know you have a
	multidimensional vector. For example vector_get v colour y x to index
	into a 2D array of palette indices

vector_erase

	remove from a vector
	e.g. vector_erase v index

vector_clear

	empty a vector
	e.g. vector_clear v

vector_reserve

	Allocate space for at least n elements to avoid reallocations
	e.g. vector_reserve v n

Map Functions

map_set

	set a key in a map
	e.g. map_set m "key" value
	map_set can dig down into linked maps the same way as you can
	with vector_set

map_get

	get a value from a map
	e.g. map_get m output "key"
	map_get can dig down into linked maps the same way as you can
	with vector_get

map_erase

	erase a key/value pair from a map
	e.g. map_erase m "key"

map_clear

	clear a map
	e.g. map_clear m

map_keys

	Get the names of the keys from a map into a vector of strings
	e.g. map_keys m v

File Functions

file_open

	open a file, mode can be either "a" "r" or "w"
	"a" means append, "w" means write (overwrite)
	and "r" means read mode.
	e.g. number f file_open f "out.txt "w"
	f will be -1 on failure

file_close

	You should always close files you open with this
	e.g. file_close f

file_read

	Read a word from a file
	e.g. file_read f s

file_read_line

	Read a line from a file
	e.g. file_read_line f s

file_write

	Write a word to a file
	e.g. file_write f "turkey"

file_print

	Print to a file. Behaves exactly like print but takes a file
	e.g. file_print f "%(20s)%(20s)%(20s)" x y z

Bitwise Functions

|

	Bitwise or
	All bitwise functions cast the numbers to int first
	e.g. | x 128

^

	Bitwise xor
	e.g. ^ x y

&

	Bitwise and
	e.g. & x 255

<<

	Left shift
	e.g. << x 3

>>

	Right shift
	e.g. >> x 3

Other

print

	print a string (like string_format)
	e.g. print "Hello, I'm % and I like % and %" name like1 like2
	printf-equivalent formating options are available with %(...) for
	example %(3.16g)

input

	Read a word from stdin
	e.g. input str

getenv

	Get an environment variable
	e.g. getenv dest "HOME"

mkdir

	Create a directory
	e.g. mkdir my_string_path

list_directory

	List files and directories in a glob
	e.g. list_directory dest_vector "/home/Pelvis/*"
	Directories returned will end with "/" and regular files will not.

get_system_language

	Returns the user interface language of the system
	e.g. get_system_language lang
	lang will be in Steam format e.g. "french", "brazilian" etc

list_drives

	Get a list of active drive letters in a vector (e.g. "A", "C", ...)
	e.g. list_drives v

get_full_path

	Convert a pathname to a fully qualified pathname
	e.g. get_full_path filename

text_colour

	Change the text colour. Colour constants are:
		BLACK
		BLUE
		GREEN
		CYAN
		RED
		PURPLE
		YELLOW
		WHITE
	Each colour has a bright version toggleable by a boolean.
	e.g. text_colour BLACK 0 WHITE 1 ; fore fore_bright back back_bright

text_reset

	Reset the text colour
	e.g. text_reset

text_clear

	Clear the screen
	e.g. text_clear

getch

	Input a single character from the terminal, not waiting for newline
	e.g. getch input_number

Constants

Note: these values are not read-only (so not technically constant...)

These are used with text_colour: