[ANNOUNCE] Visual programming a function node with Blockly - Feedback request

I'm preferring the new syntax and structure but I think the
image

block is not quite right

I think the basic Node-RED philosophy is to take in an object called msg and output a modified version of it

So I think the send msg block should only be sending msg onwards so having the pluggable msg object is not needed (or wanted)

While that is mostly true, it isn't always so. Sometimes, you really need to know you've created a new msg object. Also, you sometimes need more than 1 msg object.

Fair enough
........................

Hi Simon,

This is weird. I have done the following test:

  • Installed my contribution from my Github repository, to make sure I have the same version as you.
  • Tried both your examples and it works fine here...

No clue what is going wrong. I had yesterday also a few issues after I changed the structure of the json blocks (since the workspace kept some info from the original structure). Could you please do the following:

  • Refresh your browser window
  • Remove the Blockly node from your flow
  • Add a new Blockly node for your test.

If it still doesn't work, please send a screenshot of the 'generated Javascript' tabsheet, and an export of your Blockly node flow ...

P.S. Good proposal to have a 'send msg' block without msg input, since that would be lot of easier to use. That is the kind of feedback I was hoping for ... But as Julian already mentioned you sometimes need to specify which message you want to send. For example when you want to resend every input message 5 times:

image

In this case it is best practice to clone the input message, before sending it. Otherwise the next node in the flow would receive 5 times the same message, which will result in conflicts when that node starts editing the content of every message ...

Bart

Or you might simply send your own object so please allow for that.

I do think this is a great addon for Node-RED and I hope that it gets promoted. I can see this being especially useful in education environments. Node-RED and Blockly would make a great next step up from Scratch. Currently students seem to have to make a leap from Scratch to Python and I think that loses a lot of people.

Hi Julian,

Thanks for the compliment. Makes me forget that I have been debugging very late last evening to fix Simon's issue :sunglasses: But indeed I also planned to promote this contribution with some 'eductational' people, which I know are using Node-Red with their students...

Is this what you mean??

blockly%20Julian

P.S. All credits for these JSON blocks go to Mark Friedman ...

1 Like

Fair enough - I don't do advanced stuff like that :slight_smile:

How about changing the labelling on the block so that it just says "send" and not "send msg"?
(as the word msg is basically a reserved word in Node-RED)

Simon

Yep, that is something I have been asking myself. Could be "send" or perhaps even better "send object", since you can only send an object (and e.g. not a number or a string ...). But indeed not "send msg".

1 Like

Confirming bug now fixed in latest version :slight_smile:

Thank you lord ... And thank you Simon, for keeping me updated ...

The text has been updated on Github:

image

We talk about sending messages not objects. Yes a message needs to be an object rather than other types, but I'd suggest either just send or send message.

Does blockly do any type checking so it can only allow joining a block that outputs an object to the send block?

Hi Nick,

Every block in Blockly 'can' do type checking, and most of the time it will be used otherwise you will run into troubles (see below). Good that you mention it, because seems that I forgot it on the node_send block. Added it now on Github:

  • Without check (null) you can link 'any' other block to it, which can result in errors during execution:

  • With check (e.g. 'Object') you can only link other blocks to it, whose output is an 'Object'. When you try to link another type to it, you will notice that you cannot drop the block at that location:
    blockly_rejected

I will need to have a label at the input of the node_send block (to explain what the input needs to be), so then it should be like below ?

image

I'd still vote for just send

but

...

All examples I see on function node JS use return(msg) so should Blockly use return and not send?

I used async sending, because otherwise I got issues when other statements were added after the node-send. For example:

image

If I would generate a return-statement at line 1, line 2 would never be executed

The end of a function uses return(msg), (or return(null) etc) but if you need to send something asynchronously you use node.send(msg). So it depends how you want to ā€œhelpā€ students from blockly to js functions.
PS Iā€™d also vote for just ā€œSendā€ ( with type checking on )

Just a quick test. If it would be for educational purposes, I could do something like this (default asynchronous):

blockly_sync_async

But not sure if that doesn't become too complex for other users? Since a return in the middle of a program would be incorrect....

Why does a user need to pick sync vs async? That's for your generated code to figure out.

Stick with 'send' or 'send message'.

Ok, now it looks like this:
image

Another question, and then I'm off to do some parental stuff with my boys ...

At the bottom you can change the number of output ports, and in the send-block you can specify to which of those outputs the message/object needs to be send.
However the number of outputs (at the bottom) can be set to a value lower than used in the send-blocks. Or in the send blocks an output number can be specified which is higher than the number of available outputs. In both cases you try to send to an unexisting output.

In this case I generate an error in the log, since I cannot send something:

blockly_outputs

Is this a good solution, or could I do better?
Thanks !

Yup! :smile:

Well, I think Simon might be operating in this space?