Mila.gd, a very simple scripting language written in GDScript

EDIT: I renamed “Gompl” to “mila.gd”, and moved the repository to Codeberg:

/EDIT

Basically what the title says. I needed a simple way to execute game logic via our game’s dialogues and thought creating an interpreter could be fun. It don’t need it to be performant so I just used GDScript for the parser, and the amount of features is small, e.g., there are function calls, but not functions. (EDIT: Functions were added later, but they don’t support arguments.)

A script in Gompl could look like this:

x = 0 // initialise variable, otherwise it's "undefined"
while x < 10 do
    some_func(x) // "some_func" is defined in GDScript
    x = x + 1
end
if some_other_func("test") != 100 then // "some_other_func" also in GDScript defined
   "success"
else
   "fail"
end
// the last expression (either "success" or "fail" in this case)
// is returned by Gompl's eval() method
6 Likes

I updated the language a bit, for example if-then expressions can now have elifs. There are some thing I’d still like to change, e.g. removing bools and adding floats for numbers.

1 Like

I decided against removing bools (as they’re needed for calling GDScript methods), but added floats now.

1 Like

Still struggling with the use-case for this… unless you want to build some Chaos-o-Matic 3000 gamestate machine… :sunglasses:

Wondering where this is going… :metal:

Dunno, what’s not clear about the second sentence in my first post?

I improved the error messages (they show line numbers now), and also made Gompl interruptible. Either provide a maximum amount of execution steps, or use the interrupt keyword, or both.

I added functions, so now you can write something like this in Gompl:

// it doesn't matter where the function is defined
function sum() // parameters are not (yet?) supported
	a + b // the last expression is the return value
end

a = 4
b = 8
c = sum() + sum() // c is 24

I added functions mostly because SmallBasic had them too, the language I really liked to use in Unity.

1 Like

I had some time to work on Gompl, so I added support for arrays.

// Arrays are initialised via array()
a = array(1, 2, 3, 4, 5)
a[2] = "hello"
a.append(-5).sort() // support currying because why not
a.pick_random() // result is a random element

Godot’s dictionaries are supported now, too.

function dict_test()
  d = dictionary("b": 2, "a": 1)
  d.set("c": 3).sort() // d is now { "a": 1, "b": 2, "c": 3 }
  d["a"] // function returns 1
end

// if you don't use the key value pairs, dictionaries can be used as hashsets
function set_test()
  s = dictionary(2, 3, 5, 7)
  s.has(11) // returns false
end

I renamed my little interpreter to mila.gd and migrated the repository to Codeberg.

And I added two more things:

A) Iteration via while i of x do … end, where x can be an array, a dictionary, a string or a number.

B) Internal functions can now have parameters:

function div(a, b)
	if b == 0 then stop with "Division by zero!" end
	a / b
end
print(div(12, 0))

mila.gd is being used in our current game project, Mops & Mobs , for almost everything related to quest logic. I call short script snippets via Godot nodes, often from our dialog system: