Discuss Scratch
- Discussion Forums
- » Open Source Projects
- » how to add a custom block on scratch-vm
- sciclass
-
2 posts
how to add a custom block on scratch-vm
scratch-vm is a great project . but when i using it .i meet some questions about adding custom block on it .
in playground.js: i add a block like this
window.Blockly.Blocks = {
init: function() {
this.appendDummyInput()
.appendField(“test”);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setColour(210);
this.setTooltip('');
this.setHelpUrl('http://www.example.com/');
}
in Scratch3MotionBlocks i add the block config
Scratch3MotionBlocks.prototype.getPrimitives = function () {
return {
motion_test: this.smove,
motion_movesteps: this.moveSteps,
motion_gotoxy: this.goToXY,
motion_goto: this.goTo,
motion_turnright: this.turnRight,
motion_turnleft: this.turnLeft,
motion_pointindirection: this.pointInDirection,
motion_pointtowards: this.pointTowards,
motion_glidesecstoxy: this.glide,
motion_ifonedgebounce: this.ifOnEdgeBounce,
motion_setrotationstyle: this.setRotationStyle,
motion_changexby: this.changeX,
motion_setx: this.setX,
motion_changeyby: this.changeY,
motion_sety: this.setY,
motion_xposition: this.getX,
motion_yposition: this.getY,
motion_direction: this.getDirection
};
};
Scratch3MotionBlocks.prototype.test = function (args, util) {
var steps = Cast.toNumber(args.STEPS);
var radians = MathUtil.degToRad(90 - util.target.direction);
var dx = steps * Math.cos(radians);
var dy = steps * Math.sin(radians);
util.target.setXY(util.target.x + dx, util.target.y + dy);
};
but when i running the server ,i cant find the my custom block?
so i dont' know what happen, need i modify the scratch-block' code?
what should i do slove it? million of thx
in playground.js: i add a block like this
window.Blockly.Blocks = {
init: function() {
this.appendDummyInput()
.appendField(“test”);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setColour(210);
this.setTooltip('');
this.setHelpUrl('http://www.example.com/');
}
in Scratch3MotionBlocks i add the block config
Scratch3MotionBlocks.prototype.getPrimitives = function () {
return {
motion_test: this.smove,
motion_movesteps: this.moveSteps,
motion_gotoxy: this.goToXY,
motion_goto: this.goTo,
motion_turnright: this.turnRight,
motion_turnleft: this.turnLeft,
motion_pointindirection: this.pointInDirection,
motion_pointtowards: this.pointTowards,
motion_glidesecstoxy: this.glide,
motion_ifonedgebounce: this.ifOnEdgeBounce,
motion_setrotationstyle: this.setRotationStyle,
motion_changexby: this.changeX,
motion_setx: this.setX,
motion_changeyby: this.changeY,
motion_sety: this.setY,
motion_xposition: this.getX,
motion_yposition: this.getY,
motion_direction: this.getDirection
};
};
Scratch3MotionBlocks.prototype.test = function (args, util) {
var steps = Cast.toNumber(args.STEPS);
var radians = MathUtil.degToRad(90 - util.target.direction);
var dx = steps * Math.cos(radians);
var dy = steps * Math.sin(radians);
util.target.setXY(util.target.x + dx, util.target.y + dy);
};
but when i running the server ,i cant find the my custom block?
so i dont' know what happen, need i modify the scratch-block' code?
what should i do slove it? million of thx
- NitroCipher
-
500+ posts
how to add a custom block on scratch-vm
scratch-vm is a great project . but when i using it .i meet some questions about adding custom block on it .
in playground.js: i add a block like this
window.Blockly.Blocks = {
init: function() {
this.appendDummyInput()
.appendField(“test”);
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setColour(210);
this.setTooltip('');
this.setHelpUrl('http://www.example.com/');
}
in Scratch3MotionBlocks i add the block config
Scratch3MotionBlocks.prototype.getPrimitives = function () {
return {
motion_test: this.smove,
motion_movesteps: this.moveSteps,
motion_gotoxy: this.goToXY,
motion_goto: this.goTo,
motion_turnright: this.turnRight,
motion_turnleft: this.turnLeft,
motion_pointindirection: this.pointInDirection,
motion_pointtowards: this.pointTowards,
motion_glidesecstoxy: this.glide,
motion_ifonedgebounce: this.ifOnEdgeBounce,
motion_setrotationstyle: this.setRotationStyle,
motion_changexby: this.changeX,
motion_setx: this.setX,
motion_changeyby: this.changeY,
motion_sety: this.setY,
motion_xposition: this.getX,
motion_yposition: this.getY,
motion_direction: this.getDirection
};
};
Scratch3MotionBlocks.prototype.test = function (args, util) {
var steps = Cast.toNumber(args.STEPS);
var radians = MathUtil.degToRad(90 - util.target.direction);
var dx = steps * Math.cos(radians);
var dy = steps * Math.sin(radians);
util.target.setXY(util.target.x + dx, util.target.y + dy);
};
but when i running the server ,i cant find the my custom block?
so i dont' know what happen, need i modify the scratch-block' code?
what should i do slove it? million of thx
How do you set up the scratch vm in the first place?
- mewtaylor
-
100+ posts
how to add a custom block on scratch-vm
How do you set up the scratch vm in the first place?
Check out the readme on the repo to find out – https://github.com/LLK/scratch-vm. If you're having any trouble with that, definitely let me know and I'll see if I can help!
- connor24
-
3 posts
how to add a custom block on scratch-vm
There is 1 problem I see with your code:
1. You did not add the block to the toolbox, if you check Blockly.Blocks.defaultToolbox, you can add blocks. To see this variable, go to the scratch-blocks repo and go to blocks_vertical/default_toolbox.js
1. You did not add the block to the toolbox, if you check Blockly.Blocks.defaultToolbox, you can add blocks. To see this variable, go to the scratch-blocks repo and go to blocks_vertical/default_toolbox.js
- Discussion Forums
- » Open Source Projects
-
» how to add a custom block on scratch-vm