SNEK is a very simple scripting language that you can use to control cutscenes or anything that you want really in your games. The entire language is set up to run as a coroutine, so that one command can take as lont as it wants.
You can use your own single frame frunctions via the @snek_command decorator, which will convert to a coroutine for you. You can also create your own multiple frame callbacks by sublcassing the SnekCommand class and implementing a get_value()
method.
The language is centered around being as powerful as possible while still being simple and easy to parse.
Comments are denoted by a #
, strings by "
or '
on each side. There are no multiline comments.
x = 2;
sets x to 2
y = 2 + 3;
sets y to the sum of 2 and 3
print("Hello world!");
prints the string "hello world!"
There are many other functions that you have access to as well:
upper(string)
is the equivalent ofstring.upper()
in pythonlower(string)
is the equivalent ofstring.lower()
in pythontitle(string)
is the equivalent ofstring.title()
in pythonprint(*stuff)
is like python but gives a little debug infowait(time)
is the same astime.sleep(time / 1000)
orpygame.time.delay(time)
randint(start, end)
is the same asrandom.randint(start, end)
input(prompt)
is special. It is the one function that blocks even the async part of the code. It is used for console demos and for halting things for debugging purposes. It is equivalent to the pythoninput()
functionnot(arg)
is the same as thenot
operator in pythonnot(True)
=False
bool
does the same as in python as wellcontains(string, substring)
is the same assubstring in string
in python
SNEK has three control flow statements, which would act pretty much how you would expect: If statement:
# if statement runs its code if bool(x) == True
if x {
print("x evals to true!");
}
# if x is 0, print x is 0. If it is 1, print it
switch x {
case 0 {
print("x is 0");
}
case 1 {
print("x is 1");
}
}
SNEK has three variable types as well. They are all represented the same way python represents them, but you can only call their methods if you wrap them into commands. You are also permitted to add custom types. All you need to do is create a constructor for them and add it to the API, as well as any commands that work with that type.
x = 0; # x is an int
y = -.6 # y is a float
z = "Hello, world!" # z is a string