imagicbell / ublockly

reimplementation of google blockly for Unity
http://imagicbell.github.io/unity/2017/10/11/blockly-one.html
Apache License 2.0
138 stars 52 forks source link

Compiler to check errors #14

Open toamig opened 3 years ago

toamig commented 3 years ago

Hello again!

We have a huge doubt that can require some work, but we would like to know your opinion and to get some advice.

For our game we want to verify if the code has any errors like missing inputs before running the code, to ensure we can perform a state transition and actually run the code without running into errors if the user forgets something. Do you think it is easy or even possible to make kind of a compiler to iterate through all blocks of code and search for those kind of errors before having to actually execute the code?

Thanks in advance!

toamig commented 3 years ago

Hey there! We could use a little help on this, thanks in advance!

imagicbell commented 3 years ago

Hi! This is a good point and I can confirm that it is possible. In my mind, there should be the following steps:

  1. Start from the top blocks, which can get by workspace.GetTopBlocks(true).
  2. Iterate through all the blocks, like the iteration for running code.
  3. For each block, we can validate it by the logic models. A block may have Input, Connection. A Input may have Field. So you can dig into the hierarchy and validate each logic model.
  4. Maybe it is a good idea to implement a validation function for each logic model. Also the validation function of parent node may call the validation functions of its children.

hierarchy of blocks:

  • Block(Topmost in workspace)
    • ConnectionOutput
    • ConnectionPrev
    • ConnectionNext
    • Block(Next)
    • Input
    • Field
    • Field ...
    • ConnectionInput
      • Block(Input)
    • Input ...
  • Block ...
  • Block ...

PR are welcomed!