Custom Logic Blocks
As you probably know by now, unbound ships with a library of built-in logic blocks. But you're not limited to working from that set.
Logic blocks can be created from scratch or remixed from other blocks, be they from unbound itself or other members of the community.
Creating Custom Logic Blocks
Just like adding built-in logic blocks or logic boards, you can create logic blocks of your own by dragging a new logic block from the library. You must be in the Play Tab, of course.
This will give you a blank slate to start from. No name, no I/O... just a power button and endless possibilities
Let's change the default name from block1 and then click edit logic
This will open the internal code editor (if you haven't already set unbound to use an external editor) which will display the boilerplate code.
This boilerplate code is covered in more detail in the article on Logic Programming. For now, let's just uncomment line 7 and line 9 to reveal our first input and output (I/O). Delete the double dashes to turn those lines from comments into actual code then press the orange SAVE button to update.
Now we've got one input that expects an entity and an output that will contain a number. Because this logic block has no internal logic it won't do anything yet, but now these variables are accessible to use as myEntity and myOut within this block of code!
For a breakdown of what schema, start(), and update() do read the article on Logic Programming.
Remixing Logic Blocks
If you'd like to modify or build on top of a built-in logic block, you can do that as well. Let's go through an example of adding a doubleTime output to the built-in timer block. This will give us access to an output that's moving twice as fast as the time output it came with.
Once you have the timer block in your scene, click the edit logic button and then the remix icon.
This will create a copy of the logic block that you can edit without affecting the original block. Notice the new title, which you can change to whatever you want.
From here you could click the open in external editor icon to work in another code editor. For this example we're going to keep it simple and stay within unbound. We're only going to make a few changes.
First, we're going to need to define a new output. Let's call it doubleTime and give it a type of number. We can copy the time output and just rename that.
Now let's scroll down to the update() function, which runs once per frame, and add a new line that sets doubleTime to twice the time output.
Now if we click save and close the code editor we have a remixed version of the timer block that gives us access to a 2x time output.
Note
Could you feed the timer out into a calculator and double the time that way? Absolutely! But if you need regular access to a 2x version of the timer, it might be preferable for you to do it this way and have one less logic block in your scene.
Or you might need to add more complex functionality to this (or another) block. The process would be the same but the internal logic might be more involved.
This block now belongs to your internal logic library, allowing you to drag additional copies of it into your project just as you would any other block.
For a breakdown of what schema, start(), and update() do read the article on Logic Programming.