question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get block input_value's for generators

See original GitHub issue

How can we access the blocks input values in a generator?

Here is the Motion - Move Steps block definition:

Blockly.Blocks['motion_movesteps'] = { init: function() { this.jsonInit({ "message0": "move %1 steps", "args0": [ { "type": "input_value", "name": "STEPS" } ], "category": Blockly.Categories.motion, "extensions": ["colours_motion", "shape_statement"] }); } };

if we create a generator for this block as:

Blockly.Python['motion_movesteps'] = function(block) { var duration = block.getFieldValue('STEPS'); return duration + '\n'; };

we would want the getFieldValue function to return the input value on the block. However the duration variable returns null.

I noticed in the Scratch block definition the type is ‘input_value’, as oppose to ‘field_value’ in Blockly, and that in the xml generated for that block the input value actually appears inside a ‘shadow’ tag.

So, is there is simple way to access this input value via the generator?

Many thanks for the help…

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
smaamericommented, Sep 11, 2017

Sorry, have solved this.

Was using getFieldValue instead of valueToCode.

Changing to valueToCode in the generator has solved the problem. Final line to get input value looks like:

var duration = Blockly.Python.valueToCode(block, 'STEPS', Blockly.JavaScript.ORDER_ATOMIC) || '0'

0reactions
joseephcommented, Sep 13, 2017

@smaameri thank you so much for detailed explanation, in my case I just wanna define a common block with a text input field in horizontal mode, then get the input value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get value of variable in code generator - Google Groups
We are trying to get the value of a variable in our custom block's code generator. It looks something like this: Blockly.
Read more >
Custom Entity Generator Block with Signal Input ... - MathWorks
This example shows how to create a custom source block that generates entities and to manage discrete states when implementing the discrete-event System ......
Read more >
Generating Code | Blockly - Google Developers
This function finds the block connected to the named value input ('FROM'), generates the code for that block, and returns the code as...
Read more >
Pulse Generator (Simulink Reference)
All the waveform parameters must have the same dimensions after scalar expansion. The data type of the output is the same as the...
Read more >
MCode - 2020.2 English - Xilinx
An MCode block based on the function xlmax will have input ports x and y and output ... The only supported data type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found