Re: How to get value of next statement?

419 views
Skip to first unread message
Message has been deleted

Amber B

unread,
Jan 28, 2020, 9:13:35 AM1/28/20
to Blockly
Is there a reason that using workspaceToCode won't work for your setup? That will automatically generate the code for each block in the workspace in sequence, so each block can just generate its own code without worrying about previous or next blocks.

Coda Highland

unread,
Jan 28, 2020, 9:35:27 AM1/28/20
to blo...@googlegroups.com
You're looking for blockToCode, not statementToCode. blockToCode follows down the chain of connections.

/s/ Adam

On Tue, Jan 28, 2020 at 4:25 AM Agrawal <agrawalpr...@gmail.com> wrote:
Hi All,


I am using custom block in my project and want to perform some action on click of an element. I am using next statement to perform some action but I don't know how to get value of next statement in custom block for JavaScript. Blockly.JavaScript.statementToCode is working for StatementInput but What method should use for next statement. Here I am pasting the UI of my block:
Capture-2.PNG








Thanks

--
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/81cec872-0229-4982-b724-42ac42f9a3af%40googlegroups.com.
Message has been deleted

Coda Highland

unread,
Jan 29, 2020, 12:36:59 PM1/29/20
to blo...@googlegroups.com
Perhaps the problem is with your generators instead, then. What do the definitions and generators of those blocks look like?

/s/ Adam

On Wed, Jan 29, 2020 at 2:36 AM Agrawal <agrawalpr...@gmail.com> wrote:
Thanks for your reply but I have tried workspaceToCode as well as blockToCode but failed to get the expected output, may be I don't know how to use it properly. I am writing my expected output of above blogs, so it will be easy to understand the question: 

document.getElementById("button-0").onclick = function(){
    document.getElementById("panel-0-0").style.backgroundColor  = '#ff0000'
    /*** I want to attach many blocks below my first block and want their value here **/
}

And I am new to blockly, So If it is possible then please send me one example to develop these things. It will be very helpful for me.

Thanks

--
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.
Message has been deleted
Message has been deleted

Coda Highland

unread,
Jan 31, 2020, 12:59:35 AM1/31/20
to blo...@googlegroups.com
This is going to be difficult without a statement input. It's not impossible (I do it in my project) but there's no way to get Blockly's generators to put the } at the end without using a statement input. (My project doesn't generate code for the block at the top of the function -- rather, it uses those blocks to find function definitions in the workspace, generates the code for the children, and wraps the result in a function.)

If you're not using a statement input, you shouldn't be trying to capture the code for the following blocks within the generator. Blockly is responsible for following the next statement connections on its own.

/s/ Adam

//

On Thu, Jan 30, 2020 at 11:52 PM Agrawal <agrawalpr...@gmail.com> wrote:
Hi I am sending you the code of first block "simpleEvent" in which I have used appendStatementInput and it is working fine for that but I dont want to use appendStatementInput and want output like it is coming right now:

:

CODE: 

Blockly.Blocks['simpleEvent'] = {
      currentValue: -1,
      init: function() {
        this.appendDummyInput()
            .appendField('On')
            .appendField(new Blockly.FieldDropdown(this.getElementIdLstthis.elementSelectionListener), 'ElementId')
            .appendField('Event')
            .appendField(new Blockly.FieldDropdown(
              this.generatePropertyOptionsthis.elementAttributeListener
            ), 'EventId')

        this.setColour(160)
        this.setNextStatement(true)
        this.setPreviousStatement(true)
        this.appendStatementInput('DO')

        this.currentValue = this.getFieldValue('ElementId')
      },



Blockly.JavaScript['simpleEvent'] = function(block) {    
      var code = '';
      if(block.getFieldValue('ElementId')){
        let elementId = block.getFieldValue('ElementId')
        if(block.getFieldValue('EventId') == 'CLICK'){
          code += 'document.getElementById("'+elementId+'").onclick = function(){\n'
        }else if(block.getFieldValue('EventId') == 'OnDblClick'){
          code += 'document.getElementById("'+elementId+'").ondblclick = function(){\n'
        }else if(block.getFieldValue('EventId') == 'MouseOver'){
          code += 'document.getElementById("'+elementId+'").onmouseover = function(){\n'
        }else if(block.getFieldValue('EventId') == 'MouseLeave'){
          code += 'document.getElementById("'+elementId+'").onmouseleave = function(){\n'
        }

        var statements_name = Blockly.JavaScript.statementToCode(block'DO');

        if(statements_name){
          code += Blockly.JavaScript.INDENT+statements_name+'\n';
        }
        
        code += '}\n'
      }
      return code
    } 

OUTPUT:

document.getElementById("button-0").onclick = function(){

    document.getElementById("panel-0-2").style.display = (((document.getElementById("panel-0-1").style.display == "none" ? false: true)==true||(document.getElementById("panel-0-1").style.display == "none" ? false: true)=="true"||(document.getElementById("panel-0-1").style.display == "none" ? false: true)==1||(document.getElementById("panel-0-1").style.display == "none" ? false: true)=="1")?"block":"none");

  document.getElementById("panel-0-2").style.backgroundColor  = '#ff0000'

}

--
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.
Message has been deleted

Coda Highland

unread,
Jan 31, 2020, 1:53:31 AM1/31/20
to blo...@googlegroups.com
That's the easiest way to do it, yes.

/s/ Adam

On Fri, Jan 31, 2020 at 12:16 AM prateek agrawal <agrawalpr...@gmail.com> wrote:
Hi, 
thanks for the clarification. It means I should still use statement input instead of next statement?

--
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.
Reply all
Reply to author
Forward
0 new messages