Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Snap! user discussion
- liam48D
- Scratcher
1000+ posts
Snap! user discussion
I don't know what's happened to this world, with even the original posters spamming on their own topics.. ◀◀◀▶▶▶
202e-202e-202e-202e-202e UNI-CODE~~~~~
- xly
- Scratcher
100+ posts
Snap! user discussion
How do you make lists in the blocks?define my question
ask [How do you make lists work?] and wait 1 week // category=sensing
One possible solution is to define your list as a long formatted string “www”,“yyyy”,“zzzz” SET to a SCRIPT VARIABLE in your block-list
Then Snap! has all the necessary tools to process this string and report it as a “true” LIST.
This block-list can be saved, exported and re-imported like a block.
I suggest to load the reimported list into a local list to avoid the long decoding process each time you need to explore it.
My understanding of the question was : how to easily save (or export) a list of data without saving a whole project, considering that Snap! is not convenient to export/import list of data. The way I mention allows to export a list of data embedded into a block, which can be easily exported/imported.
I use this method to store a list of 140 colours having a standardized name like aquamarine,coral…(name+hexa colour value).
- liam48D
- Scratcher
1000+ posts
Snap! user discussion
I've been having trouble with returning a command. I want my command to optionally take an input - resolve value - but I get an error trying to access that variable if it wasn't passed.
The command looks like this:
Is there any way to make a command/reporter take an optional value? I can mimic the ideal effect like so:
The command looks like this:
(command) args: (resolve value) :: grey hatWhen I run it like this, it works:
say (join [It's done, with value: ] (resolve value)
run (command) with arguments [Foo] :: control // "It's done, with value: Foo"But when I run it like this:
run (command) :: control // should be "It's done, with value: "..I get an error: a variable of name ‘resolve value’ does not exist in this context.
Is there any way to make a command/reporter take an optional value? I can mimic the ideal effect like so:
run (command) with arguments [] :: control // "It's done, with value: "But that really doesn't look nice.
202e-202e-202e-202e-202e UNI-CODE~~~~~
- ChocolatePi
- Scratcher
1000+ posts
Snap! user discussion
Couldn't you just make another command that doesn't take an argument
- liam48D
- Scratcher
1000+ posts
Snap! user discussion
Not really, because the command is returned from a custom block. Couldn't you just make another command that doesn't take an argument
202e-202e-202e-202e-202e UNI-CODE~~~~~
- ChocolatePi
- Scratcher
1000+ posts
Snap! user discussion
You mean you're returning a function?Not really, because the command is returned from a custom block. Couldn't you just make another command that doesn't take an argument
Show us all the code, kid! (just kidding we're the same age)
- bharvey
- Scratcher
1000+ posts
Snap! user discussion
The only thing I can think of is to make it a variadic input. (Click the “multiple inputs” button in the long form input dialog.) Is there any way to make a command/reporter take an optional value?
- liam48D
- Scratcher
1000+ posts
Snap! user discussion
Oops, I mean the ring block!The only thing I can think of is to make it a variadic input. (Click the “multiple inputs” button in the long form input dialog.) Is there any way to make a command/reporter take an optional value?
EDIT: This seems to work:
run (the script ::grey ring) :: controlUnfortunately I can't see how it would work with multiple inputs.
run (the script ::grey ring) with inputs [Foo] :: control
the script :: grey hat
script variables (input) :: grey
set [input v] to []
say (join [input is: ] (input)) for (1) secs
Last edited by liam48D (Jan. 7, 2016 01:25:31)
202e-202e-202e-202e-202e UNI-CODE~~~~~
- ChocolatePi
- Scratcher
1000+ posts
Snap! user discussion
I can't wait until first-class costumes where I can make an ironic “engraved invitation” function that returns an actual engraved invitation!
- bharvey
- Scratcher
1000+ posts
Snap! user discussion
Oh. Yeah, you don't get long form input dialogs with rings (but you should, @Jens). Sorry. Unfortunately I can't see how it would work with multiple inputs.
- bharvey
- Scratcher
1000+ posts
Snap! user discussion
It's text boxes you can't wait for. Me neither. (A text box will be a special kind of costume that contains text instead of pixels, and can be edited either by the user clicking in it or programmatically.) I can't wait until first-class costumes where I can make an ironic “engraved invitation” function that returns an actual engraved invitation!
- Jens
- Scratcher
100+ posts
Snap! user discussion
Snap doesn't have optional inputs, as many other programming languages don't have optional parameters either. But - like other programming languages, too - Snap lets you be explicit about what you want to do. You should be able to infer the type or value of the “optional” argument and depending on that either execute “RUN” or “RUN WITH INPUTS”. What do you think?
- liam48D
- Scratcher
1000+ posts
Snap! user discussion
Yeah, but maybe add a null block. Though null can be worked around like this: Snap doesn't have optional inputs, as many other programming languages don't have optional parameters either. But - like other programming languages, too - Snap lets you be explicit about what you want to do. You should be able to infer the type or value of the “optional” argument and depending on that either execute “RUN” or “RUN WITH INPUTS”. What do you think?
(null :: operators) :: control hat
report (call (JavaScript function [return null] :: operators) :: control) :: control cap
202e-202e-202e-202e-202e UNI-CODE~~~~~
- liam48D
- Scratcher
1000+ posts
Snap! user discussion
Nor IMe neither
Me neither
202e-202e-202e-202e-202e UNI-CODE~~~~~
- s_federici
- Scratcher
500+ posts
Snap! user discussion
What is this? I couldn't find it even in http://snap.berkeley.edu/snapsource/dev/snap.html
- djdolphin
- Scratcher
1000+ posts
Snap! user discussion
I'm pretty sure it's enabled by default now and the setting was removed. The when <> block is in the control category.What is this? I couldn't find it even in http://snap.berkeley.edu/snapsource/dev/snap.html
!
- s_federici
- Scratcher
500+ posts
Snap! user discussion
I see thanks I'm pretty sure it's enabled by default now and the setting was removed. The when <> block is in the control category.