basic custom block don't work

266 views
Skip to first unread message

luis....@ecci.edu.co

unread,
Sep 10, 2018, 7:01:51 PM9/10/18
to Blockly
Hi firiends, I've being working in blockly custom block using blockly developer tools, I need to charge python code form one of my files into this code, when I try to execute blockly with my custom block this is not executed. Someone can help me to solve this problem?

Andrew n marshall

unread,
Sep 10, 2018, 7:30:10 PM9/10/18
to blo...@googlegroups.com
Hi,

So we can help you, can you please include some example code That you've tried, a description of the steps you've taken, and the results of those steps?

luis yaya garcia

unread,
Sep 12, 2018, 5:28:27 PM9/12/18
to blo...@googlegroups.com
Hi dear, i've doing three phases,

first: i create a block using blockly developers tools, i've making basic example (i'm trying to print a variable) no more





second, I take code, block definition, i put this code into a new js file in /blockly/blocks folder and generator stub code (python selected ) i put it new js file (same name than block definition file) in /blockly/generators folder

Blockly.Blocks['block_type'] = {
  init: function() {
    this.appendValueInput("print")
        .setCheck(null)
        .appendField("print");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(230);
 this.setTooltip("");
 this.setHelpUrl("");
  }
};

here, I change code for print my variable using python
Blockly.Python['block_type'] = function(block) {
  var value_print = Blockly.Python.valueToCode(block, 'print', Blockly.Python.ORDER_ATOMIC);
  // TODO: Assemble Python into code variable.
  var code = print(
  return code;
};

Blockly.Python['text'] = function(block) {
// Text value.
var code = Blockly.Python.quote_(block.getFieldValue('TEXT'));
return [code, Blockly.Python.ORDER_ATOMIC];
};
I Include too in the index.html file new category, then i put my new block in workspace and put too several predefinided blocks but when i press play button nothing happen, but if I quit my custom block everything works full.

I don't know why

I appreciate all your help. 

 


--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Cordialmente,




Logo Ecci Universidad Colombia

Luis Gabriel Yaya Garcia

Investigador
Lab. Diseño y Fabricación de Circuitos y Sistemas Electrónicos
Vicerrectora de Investigación
Teléfono: (571) 3537171 ext. 188
www.ecci.edu.co
Carrera 19 No. 49–20 Bogotá, Colombia

Facebook Ecci universidad colombia Twitter Ecci universidad colombia Instagram Ecci universidad colombia Youtube Ecci universidad colombia

 



AVISO: Los servicios del correo ecci.edu.co son soportados tecnológicamente por © Google para toda la comunidad de la Universidad ECCI (Administrtivos, Docentes y Estudiantes), las opiniones que contenga este mensaje son exclusivas de su autor y no representan necesariamente la opinión de la Universidad ECCI. La Universidad ECCi no garantiza la utilización de un antivirus ya que se menciona los servicios son soportados © Google, si su antivirus detecta alguna anomalía por favor reportelo y elimine, la Universidad no se responsabiliza por los daños causados por cualquier virus transmitido en este correo electrónico.

La información contenida en este mensaje y en los archivos adjuntos es confidencial y reservada y está dirigida exclusivamente a su destinatario, sin la intención de que sea conocida por terceros, por lo tanto, de conformidad con las normas legales vigentes, su interceptación, sustracción, extravío, reproducción, lectura o uso esta prohibido a cualquier persona diferente. Se les exige expresamente a la comunidad ECCI (Administrtivos, Docentes y Estudiantes) que no realicen declaraciones difamatorias, no infrinjan ni autoricen ninguna infracción de las leyes de propiedad intelectual o cualquier otro derecho legal mediante comunicaciones por correo electrónico.La Universidad ECCI no garantizar guardar una copia de respaldo de los archivos, correos.

Si por error ha recibido este mensaje por favor discúlpenos, notifiquenoslo y elimínelo.

AVISO: Los servicios del correo ecci.edu.co son soportados tecnológicamente por © Google para toda la comunidad de la Universidad ECCI (Administrtivos, Docentes y Estudiantes), las opiniones que contenga este mensaje son exclusivas de su autor y no representan necesariamente la opinión de la Universidad ECCI. La Universidad ECCi no garantiza la utilización de un antivirus ya que se menciona los servicios son soportados © Google, si su antivirus detecta alguna anomalía por favor reportelo y elimine, la Universidad no se responsabiliza por los daños causados por cualquier virus transmitido en este correo electrónico.

La información contenida en este mensaje y en los archivos adjuntos es confidencial y reservada y está dirigida exclusivamente a su destinatario, sin la intención de que sea conocida por terceros, por lo tanto, de conformidad con las normas legales vigentes, su interceptación, sustracción, extravío, reproducción, lectura o uso esta prohibido a cualquier persona diferente. Se les exige expresamente a la comunidad ECCI (Administrtivos, Docentes y Estudiantes) que no realicen declaraciones difamatorias, no infrinjan ni autoricen ninguna infracción de las leyes de propiedad intelectual o cualquier otro derecho legal mediante comunicaciones por correo electrónico.La Universidad ECCI no garantizar guardar una copia de respaldo de los archivos, correos.

Si por error ha recibido este mensaje por favor discúlpenos, notifiquenoslo y elimínelo.

Rachel Fenichel

unread,
Sep 13, 2018, 6:54:37 PM9/13/18
to Blockly
This line in your generator doesn't make sense:
var code = print(

Was that a copy-paste error, or is that the code that you are running?

If you open the browser's developer tools and look at the console, are you seeing any error messages?

Cheers,
Rachel

luis yaya garcia

unread,
Sep 14, 2018, 4:02:33 PM9/14/18
to blo...@googlegroups.com
Yes, i was a mistake copying this code, I'm so crazy jejejeje

Only i want to print

correct code is


Blockly.Blocks['texto'] = {
  init: function() {
    this.appendValueInput("NAME")
        .setCheck(null)
        .appendField("print");
    
this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(230);
 this.setTooltip("");
 this.setHelpUrl("");
  }
};
here, I change code for print my variable using python

Blockly.JavaScript['texto'] = function(block) {
  var value_name = Blockly.JavaScript.valueToCode(block, 'NAME', Blockly.JavaScript.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  var code = value_name;
  return code;
};

In this point i donk now how to include or execute python code, in my example only i
want to print a simple variable


--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Cordialmente,




Logo Ecci Universidad Colombia

Luis Gabriel Yaya Garcia

Investigador
Lab. Diseño y Fabricación de Circuitos y Sistemas Electrónicos
Vicerrectora de Investigación
Teléfono: (571) 3537171 ext. 188
www.ecci.edu.co
Carrera 19 No. 49–20 Bogotá, Colombia

Facebook Ecci universidad colombia Twitter Ecci universidad colombia Instagram Ecci universidad colombia Youtube Ecci universidad colombia

 


Erik Pasternak

unread,
Sep 17, 2018, 1:12:28 PM9/17/18
to Blockly
So to help with debugging you could add a console.log statement to the code generation: Note, as written your block will return whatever code is generated by the block attached to it. If there's not a block attached to it it will return an empty string.

Blockly.JavaScript['texto'] = function(block) {
  var value_name = Blockly.JavaScript.valueToCode(block, 'NAME', Blockly.JavaScript.ORDER_ATOMIC); // TODO: Assemble JavaScript into code variable.
  var code = value_name;
  console.log(code);
  return code;
};

For the python version, you'd want something like

Blockly.Python['texto'] = function(block) {
  // Text value.
  var value_name = Blockly.JavaScript.valueToCode(block, 'NAME', Blockly.JavaScript.ORDER_ATOMIC); 
  var code = 'print(' + value_name + ')';
  return code;
};

If you haven't before, it might help to go through the CodeLab which walks through all the steps for getting a Blockly app started and executing code. And if you're still having trouble be sure to keep the console open and check for any errors.

Cheers,
Erik
Reply all
Reply to author
Forward
0 new messages