Right, but this is a very large system with many features and complexities you will have to find and specify along the way.
Endless’ block coding plugin can be viewed publicly for free, you can read what they did, even use their code to inform how you want to build or get started on the system. Notice how much code is inside the block coding plugin? It’s multiple files across many directories and sub-systems, there isn’t an easy solution, and even getting started means building many scenes.
In Godot editor plugins can be and often are, written in GDScript, using the same systems that work in-game. The Godot editor is built using Godot systems, so code can be used for either editor or gameplay seamlessly. Therefor you can use the Block code editor plugin as a reference to code your game interface.
To get started on a system like this I’d recommend reading up on virtual machine/interpreter architecture, like this chapter on Bytecode by Robert Nystrom. Though the book focuses a lot on performance in C++ with low-level systems.
The block-based interface is just that, an interface to a programming language, of which will prove the bulk of the challenge. Making a Expression class_name to extend with your various expressions will be the first step.
extends RefCounted
class_name Expression
func evaluate() -> Variant:
return true
Then you can extend to make a “if” branching expression, and a getter expression.
extends Expression
# optionally class_name Branch
var next_success: Expression
var next_failure: Expression
var condition: Expression
func evaluate() -> Variant:
if condition.evaluate():
return next_success.evaluate()
else:
return next_failure.evaluate()
extends Expression
# optionally class_name Getter
var target_node: Node
var indexed_name: String
func evaluate() -> Variant:
return target_node.get_indexed(indexed_name)
Each expression runs it’s own code in func evaluate
, they can be as complicated or simple as you need. Building expressions into a chain will depend on how you implement your block code. I figure each placed block could contain a Expression variable, with sections to fill out each of the expressions variables. You will need many different types of expression for different types of variables.
This one code block contains many Expressions: a Branch based on a Condition (<
less than), with a Getter (for ChassisHP) and a Literal (20%). On success it will perform a MovementAction (move back).