To initialize the environment and create and register scripts with Sprites and Stages, you use the JavaScript classes directly. In most cases, you only need to write code like:
var env = new PodJS(); var scratch = env.pod("scratch"); var robot = scratch.newSprite("robot"); robot.loadCostume("costume1", "img/Cartoon_Robot_a.png"); robot.loadCostume("costume2", "img/Cartoon_Robot_b.png");In more advanced cases, you should consult the pod.js JsDocs (try looking at Sprite, for example):
Blocks are intended to behave identically to blocks in Scratch, and take the same number of parameters. See the Scratch Wiki for details. To pass parameters to blocks, just add more blocks, separating each one with dots, like so:
robot.newScript(). when_green_flag_clicked. forever.begin. costume.c("costume2"). move.c(10). wait.c(1). costume.c("costume1"). move.c(-10). wait.c(1). end;
To pass in a constant value, use the 'c' block, and provide the value in parenthesis, like c(10)
.
For advanced users, if you'd like to use pure JavaScript code in your Scratch Blocks, you can use the 'f' block, like so:
move.f(function() { return 5 + 5; }).
The following Scratch blocks are provided by pod.js. Blocks that are implemented have a checkmark next to them. Others are not yet implemented but coming soon!