Recursive programming, uh oh
Posted on 2016-01-10 03:08
So over the past week I’ve been implementing a simplistic scripting language inside Multimedia Fusion 2 to make it easier to create a versatile in-game editor for a game project. Programs like Game Maker of course already do something like this, but it felt kind of funny to realize that I was augmenting the usability of MMF2 by adding a custom-made scripting language on top of it. Designing something like this has also been an interesting lesson in programming.
Anyway, some examples of the syntax:
1.
if,node,0,3,<,0/else/goto,2
add,node,1,3,1/loop
sub,node,1,3,1/loop
When this runs, an object called "node" with the ID "1" will add 1 to it's variable at index "3" (which is its X position) if "node" with the ID "0" has its variable at index "3" below zero. Else, the "node" with ID "1" subtracts one from said variable. Or in motion:
The teal diamond is the node with ID 0, and it moves above and below the 0 X coordinate, causing the other node to move.
2.
aimrelative,node,1,4,node,0,4,0.05/loop
When this runs, the "node" with ID "1" sets its variable at index "4" (i.e. Y position) so that it approaches the value of node 0's variable 4. The 0.05 defines the speed at which the value changes, being in this case 5% of the gap between those variables. Or in motion:
Again the teal diamond is the node with ID 0.
3.
if,damage,>,1
set,surface,1,19,3/set,surface,2,19,3
set,mask,15,18,3/set,mask,16,18,3/end
This is what I actually use in-game right now. Basically it checks if an enemy is damaged enough (the 'damage' variable counts upwards because SHUTUP SHUTUP SHUTUP), its graphical masks change slightly, after which the code block stops running.
As you can see, the language is very crude and dependent of hand-crafted commands. However, I use it mostly for relatively simple checks and to spice up enemy movement, so I'm sure it'll be more than enough for this job. The fact that it supports if-else functions, and that separate code "blocks" can also affect other blocks via "start" and "pause" commands also adds a lot of versatility.
Tags: Games, Cloud Realm, Other
Return