How would I make a block based coding system like scratch on roblox?

How would i make a block based coding system like scratch on roblox, i just need an explanation and possibly an example.

1 Like

It already exists as a plugin. Can’t remember the name though sorry

2 Likes

Maybe this is the thing you’re looking for?

1 Like

Someones already given you a great example, so I’ll give you a quick explanation.

Essentially what you do is you write a transpiler, which is a translator for code to translate one language into another. In this case, your language is blocks which you want to convert into lua code. It can be quite a bit of work depending on how smart you do it, and there’s several methodologies.

Depending on the use case, the proper way to do it differs a little. Most simply and the way transpilation usually works is you would code the blocks in such a way that they have a string representation of some lua code associated with them, and then add that all together in order to get a string that can be run by loadstring.

A more game like implementation would be to create a sort of block object which everything can inherit from, this block object then has a function that can be run and inside that function is whatever relevant lua code you need to execute for that blocks behavior. If you choose this approach I’d recommend not trying to make it overly OOP like where you have a bunch of inheritance going on and objects get nested several inheritance levels deep.

To have success with this method, you need to think about what’s at the core of most programming. What are we working with? And how you can represent these things with blocks. For example variables, conditions, functions, data types.

I’d say it’s easier to get started with the second method, but much much harder to do it well. The first method is more akin to how compilers and transpilers are actually written, and not too difficult once you understand these things.

EDIT: Just noticed that the above plugin is discontinued and priced at 100000 robux, heres a link to another one BlockLua | The blazingly fast visual scripting plugin for Roblox. Code with blocks, like in Scratch!

2 Likes

I think “BlockLua” might ring some bells.

1 Like

Thank you for a quick explanation, I will try to get it working using your help and then we will go from there.

yeah as @kd3sc said i maid something. Now take in note that it takes a lot of time to be done (mine is unfinished cause i had other projects) . But i you want any help or collab idk we dm me in private chat.

Edit: How i done mine is that i have a dictionary of functions as strings that looks like this :

{["print"] = """
function block_print(message: string, next: function?) 
  print(message)
  if next then
    next()
  end
end
"""}

and then i have an other dictionary with a list of ui elements inside a block:

{["print"] = {
  {type= "label", content= "print"},
  {type="textbox", content="message", contenttype:"any"}
}
}

and then a script that will make blocks and when you compile it reads both the things, create a tree of functions … yah tell me if you got it

if you want you can try out an other of my free plugins where it compiles some nodes, and look at how it works (the compiled things are quit ez to read) to compile use enter the plugin

1 Like

yeah haha i put it to 1000000 cause i didnt want to delet it and as i didnt finish it it was stupid to give it to peaple also i hear that you can get the source of any free plugin or something like that so i prefere you know not giving it (as i sold it)