Discuss Scratch
- Discussion Forums
- » Developing Scratch Extensions
- » Is this possible
- savaka
- Scratcher
1000+ posts
Is this possible
Is there any way the extension can access variables and lists from the project?
- bobbybee
- Scratcher
1000+ posts
Is this possible
Not without a mod.
“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
- liam48D
- Scratcher
1000+ posts
Is this possible
But with Snap! you can.
202e-202e-202e-202e-202e UNI-CODE~~~~~
- savaka
- Scratcher
1000+ posts
Is this possible
But there aren't Snap! extensions. But with Snap! you can.
- liam48D
- Scratcher
1000+ posts
Is this possible
Yes there are, in the form of block libraries. They can be coded in either Snap!, JavaScript, or both simultaneously. I suggest you take a look into the JS Function block.But there aren't Snap! extensions. But with Snap! you can.
{my custom js block :: grey} :: control hat
run (JS function (code... :: grey) :: operators) :: control
// code... alert("Hello, world!");
And just for a tidbit of extra info, here's the block and code for setting a variable:
{set variable name (name) local (local = false) value (value) :: variables} :: control hat
run (JS function [var_name] [local] [value] (code... :: grey) :: operators) with inputs (name) (local) (value) :: control
if (local === "true") { // Set a LOCAL variable. All local variables are stored in // this.variables.vars so by changing this.variables.vars[var_name]'s // value attribute we can change th evalue of the variable. this.variables.vars[var_name].value = value; } else { // Set a GLOBAL variable. Same as above but changes one of the // variables stored in this.variables.parentFrame.vars. this.variables.parentFrame.vars[var_name].value = value; }
After you've made your block just click on file => export blocks and select the blocks you want to export! This will save your block(s) to an XML file. If you want people to import it, click on file => Import.. and select your XML file you or somebody else downloaded from where you uploaded the XML file.
Have fun.
202e-202e-202e-202e-202e UNI-CODE~~~~~
- savaka
- Scratcher
1000+ posts
Is this possible
But it's not an extension, it's a collection of Snap! blocks which may or may not contain JavaScript.Yes there are, in the form of block libraries. They can be coded in either Snap!, JavaScript, or both simultaneously. I suggest you take a look into the JS Function block.But there aren't Snap! extensions. But with Snap! you can.{my custom js block :: grey} :: control hat
run (JS function (code... :: grey) :: operators) :: control// code... alert("Hello, world!");
And just for a tidbit of extra info, here's the block and code for setting a variable:{set variable name (name) local (local = false) value (value) :: variables} :: control hat
run (JS function [var_name] [local] [value] (code... :: grey) :: operators) with inputs (name) (local) (value) :: controlif (local === "true") { // Set a LOCAL variable. All local variables are stored in // this.variables.vars so by changing this.variables.vars[var_name]'s // value attribute we can change th evalue of the variable. this.variables.vars[var_name].value = value; } else { // Set a GLOBAL variable. Same as above but changes one of the // variables stored in this.variables.parentFrame.vars. this.variables.parentFrame.vars[var_name].value = value; }
After you've made your block just click on file => export blocks and select the blocks you want to export! This will save your block(s) to an XML file. If you want people to import it, click on file => Import.. and select your XML file you or somebody else downloaded from where you uploaded the XML file.
Have fun.
- liam48D
- Scratcher
1000+ posts
Is this possible
But it's not an extension, it's a collection of Snap! blocks which may or may not contain JavaScript.
A Scratch extension - a collection of Scratch blocks which are coded in JavaScript.
A Snap! “extension” - a collection of Snap! blocks may or may not contain JavaScript.
Not to mention you can even make clones of the HTTP extensions in Snap! as well.
In terms of extensions (not the HTTP kind), the main difference is that with Scratch extensions you..
- .. can use hat blocks
- .. are limited to JavaScript
- .. can't interact with anything outside of your block
- .. are limited to strict hat, stack, reporter or boolean blocks
and in Snap! extensions you..
- .. can't use hat blocks
- .. can use JavaScript and normal blocks simultaneously
- .. can interact with practically anything in the morphic world of Snap! - including other scripts or sprites
- .. can create very customized block shapes and inputs (obviously excepting hat blocks)
But they generally work the same way.
202e-202e-202e-202e-202e UNI-CODE~~~~~
- savaka
- Scratcher
1000+ posts
Is this possible
But what I'm trying to say is it's not an extension, it's a file containing Snap! blocks.But it's not an extension, it's a collection of Snap! blocks which may or may not contain JavaScript.
A Scratch extension - a collection of Scratch blocks which are coded in JavaScript.
A Snap! “extension” - a collection of Snap! blocks may or may not contain JavaScript.
Not to mention you can even make clones of the HTTP extensions in Snap! as well.
In terms of extensions (not the HTTP kind), the main difference is that with Scratch extensions you..
- .. can use hat blocks
- .. are limited to JavaScript
- .. can't interact with anything outside of your block
- .. are limited to strict hat, stack, reporter or boolean blocks
and in Snap! extensions you..
- .. can't use hat blocks
- .. can use JavaScript and normal blocks simultaneously
- .. can interact with practically anything in the morphic world of Snap! - including other scripts or sprites
- .. can create very customized block shapes and inputs (obviously excepting hat blocks)
But they generally work the same way.
- Znapi
- Scratcher
500+ posts
Is this possible
A name is only a name. Both Scratch extensions and Snap! extensions are called “extensions”, but obviously they are different. But what I'm trying to say is it's not an extension, it's a file containing Snap! blocks.
If you want a Scratch extension, then you won't be able to access the variables and lists. Maybe one day some 1337 hax0r might find a way.
- savaka
- Scratcher
1000+ posts
Is this possible
Where have you seen anything official refer to any Snap! file as an “extension?”A name is only a name. Both Scratch extensions and Snap! extensions are called “extensions”, but obviously they are different. But what I'm trying to say is it's not an extension, it's a file containing Snap! blocks.
If you want a Scratch extension, then you won't be able to access the variables and lists. Maybe one day some 1337 hax0r might find a way.
- Znapi
- Scratcher
500+ posts
Is this possible
Yeah, your probably right. I'm not much of an expert on Snap!. I guess that is why liam put quotes around extension. I'd call them libraries. Where have you seen anything official refer to any Snap! file as an “extension?”
The farthest I can get on accessing variables and lists in the projects is putting “%m.list” in a block label. I guess that wouldn't be too helpful for the block if you can't access a variable when you know its name though.
- technoboy10
- Scratcher
1000+ posts
Is this possible
http://snap.berkeley.edu - scroll to "Use Devices with Snap[i!" and you'll see several extensions (which are mainly block files with a local backend).Where have you seen anything official refer to any Snap! file as an “extension?”A name is only a name. Both Scratch extensions and Snap! extensions are called “extensions”, but obviously they are different. But what I'm trying to say is it's not an extension, it's a file containing Snap! blocks.
If you want a Scratch extension, then you won't be able to access the variables and lists. Maybe one day some 1337 hax0r might find a way.
trans rights are human rights
- savaka
- Scratcher
1000+ posts
Is this possible
But they aren't called extensions. And why is this topic even open still? I'm closing ithttp://snap.berkeley.edu - scroll to "Use Devices with Snap[i!" and you'll see several extensions (which are mainly block files with a local backend).Where have you seen anything official refer to any Snap! file as an “extension?”A name is only a name. Both Scratch extensions and Snap! extensions are called “extensions”, but obviously they are different. But what I'm trying to say is it's not an extension, it's a file containing Snap! blocks.
If you want a Scratch extension, then you won't be able to access the variables and lists. Maybe one day some 1337 hax0r might find a way.
- Discussion Forums
- » Developing Scratch Extensions
- » Is this possible