How can I create my own block type like SimpleFunction?

Good morning, sir @ewpatton

I want to create a new type of block like SimpleProperty and SimpleFunction. I want the same structure like these blocks. Only I want to change the color and name it to SimpleBlock. Also, please provide me reference to some classes where blocks are written inside the app.


Sir @ewpatton, please have a look here

Adding a new block type in this way isn't really that simple, so you may want to think very strongly about your use case and whether it can be adapted to the existing structure. If you really want to continue down this path, here's a rough (possibly incomplete) sketch of what you will need to do:

  1. Add the new annotation to
  2. Update the ComponentProcessor and ComponentDescriptorGenerator classes in to handle your new annotation and add any necessary information to the simple_components.json file (produced by ComponentDescriptorGenerator)
  3. Modify blocklyeditor/src/component_database.js to handle the new structure added in step 2
  4. Add the new block definition to components.js in blocklyeditor/src/blocks
  5. Update drawer.js to generate the new block from step 4 given the description processed in step 3
  6. Add code to the YAIL generator in blocklyeditor/src/generators/yail/componentblock.js
  7. (optionally) Depending on what you're trying to do, add code to runtime.scm to handle type coercion, etc. related to your new block
1 Like

Can you elaborate the 6th point ? :sweat_smile: Which kind of code I need to add ?

YAIL is App Inventor's code language. It's essentially Scheme will additional macros (defined in runtime.scm) to make for a cleaner translation from blocks to code. For example, a method call like Notifier1.ShowAlert would translate into:

(call-component-method 'Notifier1 'ShowAlert (*list-for-runtime* "Hello World!") '(text))

You will have to generate the corresponding Scheme for the block type you intend to create.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.