eval Random Int provided Functions

89 views
Skip to first unread message

Tom Peak

unread,
May 26, 2018, 3:00:42 AM5/26/18
to Blockly
Hey,

I am making an SVG Audio Realtime Visual Programming Tool in Blockly. (Blocks like Circle/Line )
So basics works out, but I am stuck with eval provided function. fE. random int value should be pasted eval into a JSON- object with sets up SVG attributes by a function on run. (Property-Block inside a fE. LineBlock - inside a MainLoop)

It must be some basic js stuff, sorry, but I don't know how to deal with it…

Thx,

Tom
Message has been deleted

Tom Peak

unread,
May 27, 2018, 7:41:31 AM5/27/18
to Blockly


Blockly.JavaScript['property'] = function(block) {
  var text_prop = block.getFieldValue('PROP');
  var value_value = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  var value_value = eval(value_value);
  var code = '"'+text_prop+'":"' + value_value + '",';
  return code;
};

Blockly.JavaScript['circle'] = function(block) {
  var text_name = block.getFieldValue('NAME');
  var dropdown_typeX = block.getFieldValue('POSX');
  var value_x = Blockly.JavaScript.valueToCode(block, 'X', Blockly.JavaScript.ORDER_ATOMIC);
  var dropdown_typeY = block.getFieldValue('POSY');
  var value_y = Blockly.JavaScript.valueToCode(block, 'Y', Blockly.JavaScript.ORDER_ATOMIC);
  var value_r = Blockly.JavaScript.valueToCode(block, 'R', Blockly.JavaScript.ORDER_ATOMIC);
  var statements_attr = Blockly.JavaScript.statementToCode(block, 'ATTR');

   value_r = eval(value_r);
   value_x = eval(value_x);
   value_y = eval(value_y);
  // TODO: Assemble JavaScript into code variable.
  var code = "createObj('"+ text_name  + "','circle',{" + statements_attr  + "'id':'"+ text_name +"','"+dropdown_typeX+"':'"+ value_x +"','"+dropdown_typeY+"':'"+ value_y +"','r':'"+ value_r +"'})";
  return code;
};
console r= randomInt Math Block:

mathRandomInt is not defined

statementToCode?
 This is my code.

Tom

Andrew n marshall

unread,
May 29, 2018, 1:30:25 PM5/29/18
to blo...@googlegroups.com
Can I ask why you are eval'ing the results of the inputs, and then immediately concatenating the results to a string (recreating the string version of the value)?

Normally, a generator will just concatenate the valueToCode() string result so that the return code will be evaluated once as a whole.

Tom

--
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.

Tom Peak

unread,
May 29, 2018, 11:01:02 PM5/29/18
to Blockly
Yeah, thx, i got that now, I am into it. Code is "on the fly" … :) Kind against my prerender logic but I deal with it and it works out!
Making progress, It's real fun! Controlling another Window is against security, that one thing i work on later and exporting a "Patch" or how we call this? Blockly Code or … Programm as File for a External-Player. (VJ Channel)

Thx andrew, keep in contact!  

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