Discuss Scratch
- edo31415
- Scratcher
30 posts
Scratch blocks as Javascript
This is a topic for scratch blocks as JavaScript. You can add scratchblocks and what it would be as JavaScript.
if <> then
end
if () {
}
Last edited by edo31415 (July 30, 2015 01:31:31)
This post was made from edo31415
- ChocolatePi
- Scratcher
1000+ posts
Scratch blocks as Javascript
if <> then
else
end
if () {
} else {
}
repeat until <>
end
while (! ) {
}
- edo31415
- Scratcher
30 posts
Scratch blocks as Javascript
if <> then
end
if () {
}
define custom (variable)
function custom(variable) {
}
This post was made from edo31415
- edo31415
- Scratcher
30 posts
Scratch blocks as Javascript
set [Variable v] to [Hello]
var Variable="Hello"
OR
Variable="Hello"
This post was made from edo31415
- edo31415
- Scratcher
30 posts
Scratch blocks as Javascript
(length of (x))
x.length
(join [hello] [world])
"hello"+"world"
ask [Hello] and wait
set [x v] to (answer)
x=prompt("Hello")
Last edited by edo31415 (July 30, 2015 02:00:18)
This post was made from edo31415
- NickyNouse
- Scratcher
1000+ posts
Scratch blocks as Javascript
let's not forget about events:
and
when [a v] key pressed
...
window.addEventListener("keypress", function(event) { if(event.keyCode == 97) { ... } });
and
when @ clicked
...
window.addEventListener("load", function() { ... });
- liam48D
- Scratcher
1000+ posts
Scratch blocks as Javascript
Fixed let's not forget about events:when [a v] key pressed
...window.addEventListener("keypress", function(event) { if(event.keyCode == "a".charCodeAt(0)) { ... } });
202e-202e-202e-202e-202e UNI-CODE~~~~~
- liam48D
- Scratcher
1000+ posts
Scratch blocks as Javascript
forever
...
end
function myForeverLoop() { requestAnimationFrame(myForeverLoop); // ... } myForeverLoop();
Last edited by liam48D (July 30, 2015 09:19:03)
202e-202e-202e-202e-202e UNI-CODE~~~~~
- ev3coolexit987654
- Scratcher
1000+ posts
Scratch blocks as Javascript
wait (x) secs
setTimeout(, x*1000);
- tuyger
- New to Scratch
5 posts
Scratch blocks as Javascript
when I receive [ myMessage]
var myMessage = function() {
};
broadcast [ myMessage]
setTimeout(myMessage, 0);
broadcast [ myMessage] and wait
myMessage();
- WooHooBoy
- Scratcher
1000+ posts
Scratch blocks as Javascript
Try putting those in [code] blocks, like this:when I receive [ myMessage]var myMessage = function() {
};broadcast [ myMessage]setTimeout(myMessage, 0);broadcast [ myMessage] and waitmyMessage();
myMessage();
considered harmful
- powerpoint56
- Scratcher
1000+ posts
Scratch blocks as Javascript
a few more operators:
([sqrt v] of (25))
([sin v] of (90))
(round (5.2))
console.log(Math.sqrt(25)); // 5
console.log(Math.sin(90 * (Math.PI / 180))); // 1 (converts 90 degrees to radians first)
console.log(Math.round(5.2)); // 5
(letter (1) of [hello world])
"hello world".charAt(0); // "h" (the character index is zero-based, unlike Scratch)
(pick random (1) to (10))
function randomInRange(min, max) { // inclusive, like Scratch
return Math.floor(Math.random() * (max + 1 - min)) + min;
}
randomInRange(1, 10)
- __init__
- Scratcher
1000+ posts
Scratch blocks as Javascript
ftfyforever
...
endwhile (1) { // code goes here }
thisandagain pls explain
- ChocolatePi
- Scratcher
1000+ posts
Scratch blocks as Javascript
No, no, it's correct.ftfyforever
...
endwhile (1) { // code goes here }
- liam48D
- Scratcher
1000+ posts
Scratch blocks as Javascript
while (1) {} kills the browser, requestAnimationFrame redraws the browser and gets input and et cetera, so you should use that; it's the most like the forever Scratch block.No, no, it's correct.ftfyforever
...
endwhile (1) { // code goes here }
202e-202e-202e-202e-202e UNI-CODE~~~~~
- liam48D
- Scratcher
1000+ posts
Scratch blocks as Javascript
Fixed:repeat until <>
endwhile (! ) {
}
function update() { if (! /**/) requestAnimationFrame(update); // ... } update();
Last edited by liam48D (Aug. 4, 2015 00:07:47)
202e-202e-202e-202e-202e UNI-CODE~~~~~
- bobbybee
- Scratcher
1000+ posts
Scratch blocks as Javascript
Lol, I've done that a few times before. xD (accidentally of course) while (1) {} kills the browser
Same here.
I remember the time when someone hosted some encrypted messages on their website, and when I cracked it, instead of setting up a legitimate program, I pasted a blob of JS using a loop like that into the console..
whoops!
“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
- gtoal
- Scratcher
1000+ posts
Scratch blocks as Javascript
Is this for teaching javascript or is someone writing a Scratch to Javascript converter? (If the latter, then the control logic part is easy, it's the sprite system etc that's the killer…)
- liam48D
- Scratcher
1000+ posts
Scratch blocks as Javascript
Is this for teaching javascript or is someone writing a Scratch to Javascript converter? (If the latter, then the control logic part is easy, it's the sprite system etc that's the killer…)
202e-202e-202e-202e-202e UNI-CODE~~~~~