I can't get generate code about user custom function

36 views
Skip to first unread message

남승인

unread,
Dec 4, 2022, 6:30:45 PM12/4/22
to Blockly
Hello, dears~

There is one strange thing during my project development, so please contact us.

When 'Block' is selected through the 'Blockly.Events.SELECTED' event listener, there are the following parameters.

function OnSelected(event){
          var workspaceId = event.workspaceId;
          var blockId = event.blockId;
          var oldElementId = event.oldElementId; // string
          var newElementId = event.newElementId; // string
          selectedBlock = newElementId;
        }

Most of the parameters are OK, but -

User functions created inside Blockly cannot normally obtain the generated code about next.

let blockCode = Blockly.Lua.blockToCode(workspace.getBlockById(selectedBlock),true);

In most cases, normal generated code is provided as a string in 'blockCode', The user custom function does not give any value.

is this a bug? Or is this a feature not yet supported? or am i doing something wrong?

Thanks and  reguards~

Neil Fraser

unread,
Dec 4, 2022, 7:32:05 PM12/4/22
to blo...@googlegroups.com
Correct, the function definition blocks don't return code when calling blockToCode.  Instead, they add the code to a property on `JavaScript.definitions_`, before returning null.  That allows all the function definitions to be generated at the top of the program (something languages such as JavaScript don't care about, but languages such as Python really do).

See here:

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/20210b13-b173-4a38-8eb2-1ba7b211f48dn%40googlegroups.com.


--
Neil Fraser, Switzerland
https://neil.fraser.name
Reply all
Reply to author
Forward
0 new messages