How can I make a Coding System like this one?

Godot Version

godot 4.2.2

Question

I wonder if someone here could help me about how to make a Custom Coding System drag and drop like Scratch but in-game, like this example, this is an old mobile game named Toy Attack, a game about robots fight, but you can coding your robot to give you advantage in the battles

You can check this project GitHub - endlessm/godot-block-coding: Block-based visual programming plugin for Godot

I don’t think that could help me, because as far as I know, that coding block system is usually use for make a game in Godot like scratch, and I need something different, I’m looking for a way to make a custom coding system ““inside”” a game (in-game). Can you watch the video again?

Even if the plug-in is for Godot code, you can still use it as reference for your own block coding system.

how? :thinking:

how? :thinking:

I’m having difficulty understanding this question. The github link has the source code for a block coding system, written in gdscript, and you’re asking how it can be used as a reference when trying to create your own block coding system in gdscript?

Not trying to be rude, but you’re not going to get a lot of people willing to help you if you don’t show that you’ve put in some effort yourself.

1 Like

Chill Bro, I just wanna use or make a custom visual coding block system “In-Game”, and not for the engine, just for make a game like this one:


That’s all, and I already sent a video about how it works in the videogame

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).

3 Likes

OMG, thanks dude… I see that this project gonna be crazy :woozy_face:, by the way,…

I left the 4D tesseract unfinished, but I’ll post the code here in a few days, hoping someone finishes it. My intention was to create a simulation of a 4D dice🎲, but on reddit no one who knows geometry answered that question.