Page 1 of 1

How to create C-Blocks (build a launchFor block)

Posted: May 23rd, '18, 15:47
by MSandro
Hi, In this small tip I want to show you, how to customize your custom blocks. In this case, I'll show you how to use "cmd" to create C-Blocks.

1. create your block
At first, you have to build your own block. There is nothing special to consider in this step. Simply click on "Make a shared block" and build your block, as you are used to. The purpose of a C-block is to do something with code, in this particular case I show you how to use this block to execute code from another object. The function to do this, is called "launch".

Here is my block:

Code: Select all

to launchFor obj cmd {
  launch (global 'page') (newCommand 'call' (function cmd) obj) obj
}
launch.png
2. Export and edit the class
After you've finished your block, export it. This is only posible in developer mode. Now open your exported file with your prefered texteditor.

It should now look like this:

Code: Select all

spec ' ' 'launchFor' 'launchFor _ _' 'auto auto' '10' '10'

to launchFor obj cmd {
  launch (global 'page') (newCommand 'call' (function cmd) obj) obj
}

defineClass LaunchFor morph

script 'LaunchFor' 50 50 {
to launchFor {}
}
We only need the first line of the code. It contains the layout of your block. The last 3 attributes are important here: 'auto auto' '10' '10'
The 'auto auto' attribut defines the types of your input fields. In this case we want to launch code for other objects. So change the first "auto" to "obj". Our second input should be the code which we want to execute. You have to set the second "auto" to "cmd". At least, remove the last two arguments, those are only default values. You first line should now look like this:

Code: Select all

spec ' ' 'launchFor' 'launchFor _ _' 'obj cmd'
At least save and close this file and import this class in GP. If all is correct, your block should now look like this.
c-block.png
I hope this helps. Thank you for reading and have fun!

Re: How to create C-Blocks (build a launchFor block)

Posted: May 28th, '18, 19:52
by Picochilla
Thank you very much, good work! Would it be posible to implement souch functionalities directly in the BYOB?