Discuss Scratch
- Discussion Forums
- » Suggestions
- » [Suggestion] The Label Block
- ethanbros
- Scratcher
41 posts
[Suggestion] The Label Block
label: [label1 v] :: greyIn most programming languages, there are locations in code that the interpreter can jump to called “labels”. Labels exist in lots of different languages, such as BASIC, Python, et cetera.
code goes here
more code
even more code
jump to [label1 v] :: grey
With labels, the interpreter can go anywhere in scripts; all running and non-running. Please note that this block should NOT be confused with the “forever” and “repeat” blocks, as this does not have a Boolean requirement.
EXAMPLE:
Let's say that we are creating a “pick a number” game. The criteria must be between 1 and 10. If it's out of this range, the question should be repromted. The very unoptimized solution would be:
when green flag clickedAlthough this script DOES work, we can do better. We can merge the broadcast block and the stop block into a goto (jump to) block that goes to a label. Another advantage of this addon is that we can get rid of the broadcast block, which frees up good space (by not a whole lot but count the little things!)
broadcast [ask v]
when i receive [ask v]
ask [Pick a number between 1 and 10, please?] and wait
if <not <<(answer) > [0]> or <(answer) < [11]>>> then
broadcast [ask v]
stop [this script v]
end
say (answer)
when green flag clickedIn conclusion, there are advantages to putting in a label block. First, it brings the user one more step into real coding, and second, optimization can be taken even further with labels!
label [label1 v] :: grey
ask [Pick a number between 1 and 10, please?] and wait
if <not <<(answer) > [0]> or <(answer) < [11]>>> then
jump to [label1 v] and terminate :: grey cap
end
say (answer)
(However, there should NOT be a hat block for labels, otherwise, it'll just be a broadcast block.)
My account is nearing its finish.
It'll be great.
I promise.
- ACE009
- Scratcher
100+ posts
[Suggestion] The Label Block
That’s a nice way of formatting it (although you should pick a better name than label). What happens when someone does this though?
repeat (5)Does it repeat 5 times, or does it execute once? (You can’t refrence other languages for that since repeat doesn’t exist in them.) Also, I’m assuming that label creation acts the same as broadcasts.
...
label [label 1 v] :: control
...
end
jump to [label 1 v] :: control
Last edited by ACE009 (May 16, 2018 21:11:23)
when this signature read :: events hat
if <I know what [kumquats] are :: sensing> then //false
have (Katty :: pen) [eat v] [nearby kumquats v] :: motion // Katty eats the kumquats for me, whatever they are
else
learn what [kumquats] are :: sensing // this block must be malfunctional
end
- ACE009
- Scratcher
100+ posts
[Suggestion] The Label Block
I thought of what is probably the best way to handle the problem above: the label block will save the current execution state of the script (the last time it was executed), such as how many repeats are left, and then load that when it is jumped to. This also solves for whenever there are multiple label declarations in the same script.
Another problem that I thought of with that solution is what happens if the block has never been executed yet?
Another problem that I thought of with that solution is what happens if the block has never been executed yet?
when this signature read :: events hat
if <I know what [kumquats] are :: sensing> then //false
have (Katty :: pen) [eat v] [nearby kumquats v] :: motion // Katty eats the kumquats for me, whatever they are
else
learn what [kumquats] are :: sensing // this block must be malfunctional
end
- kenny2scratch
- Scratcher
500+ posts
[Suggestion] The Label Block
First of all,
Next, I'll explain why they don't exist in Python: they make code impossible to follow.
Your use case:
Python needs a redundant declaration of “answer”. Scratch does not, because all variables are pre-declared with values at the start of the program. Thus Scratch simplifies this not insignificantly.)
PythonGotos and labels do In most programming languages, there are locations in code that the interpreter can jump to called “labels”. Labels exist in lots of different languages, such as BASIC, not exist in Python.
Next, I'll explain why they don't exist in Python: they make code impossible to follow.
This is a very valid question. My intuitive answer is as follows: What happens when someone does this though?repeat (5)Does it repeat 5 times, or does it execute once?
...
label [label 1 v] :: control
...
end
jump to [label 1 v] :: control cap
repeat (5)However, it's not immediately obvious why that's the case - so it makes bugs much harder to find.
do first thing // repeats 5 times
label [label 1 v] :: control
do second thing // repeats 6 times
end
jump to [label 1 v] :: control cap
Your use case:
when gf clickedCan be replaced with this, too:
label [label 1 v] :: control
ask [Pick a number between 1 and 10] and wait
if <<(answer) < [1]> or <(answer) > [10]>> then
jump to [label 1 v] :: control cap
end
say (answer)
when gf clickedSee how simple that is? (In other languages, that wouldn't be nearly as simple. Take Python for an example:
repeat until <not <<(answer) < [1]> or <(answer) > [10]>>>
ask [Pick a number between 1 and 10] and wait
end
say (answer)
answer = 0 while answer < 1 or answer > 10: answer = int(input('Pick a number between 1 and 10: ')) print(answer)
post brought to you by the preview links bug and previously the uploads site bug. 看一下中文 Scratch 維基!想參加?請參考這頁。
- LuckyLucky7
- Scratcher
1000+ posts
[Suggestion] The Label Block
But Sublime Text 3 does have gotos, but I don't know about labels. Also, it depends on what version of python it is and what programming editor is being used. First of all,PythonGotos and labels do In most programming languages, there are locations in code that the interpreter can jump to called “labels”. Labels exist in lots of different languages, such as BASIC, not exist in Python.
- kenny2scratch
- Scratcher
500+ posts
[Suggestion] The Label Block
Sublime Text is an editor, not a programming language. Python has never had gotos (no matter what version). The programming editor does not affect the language.But Sublime Text 3 does have gotos, but I don't know about labels. Also, it depends on what version of python it is and what programming editor is being used. First of all,PythonGotos and labels do In most programming languages, there are locations in code that the interpreter can jump to called “labels”. Labels exist in lots of different languages, such as BASIC, not exist in Python.
post brought to you by the preview links bug and previously the uploads site bug. 看一下中文 Scratch 維基!想參加?請參考這頁。
- ethanbros
- Scratcher
41 posts
[Suggestion] The Label Block
That’s a nice way of formatting it (although you should pick a better name than label). What happens when someone does this though?repeat (5)Does it repeat 5 times, or does it execute once? (You can’t refrence other languages for that since repeat doesn’t exist in them.) Also, I’m assuming that label creation arcs the same as broadcasts.
...
label [label 1 v] :: control
...
end
jump to [label 1 v] :: control
Jumping from a “jump to” block to a label block should escape from the repeat block's cycle, such as what BASIC does when you enter a GOTO command in a FOR (repeat) command. If there's no label block intact, the interpreter should ignore it and go on without jumping anywhere, such as what Scratch does when the user tries to divide by 0.
My account is nearing its finish.
It'll be great.
I promise.
- GiggyMantis
- Scratcher
65 posts
[Suggestion] The Label Block
No support. It doesn't match the same style as the Scratch palette.
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
- ethanbros
- Scratcher
41 posts
[Suggestion] The Label Block
I made the block gray because I really do not know where Scratch would put it: Control? Or operators? No support. It doesn't match the same style as the Scratch palette.
Also, just giving a first glance on the block and making a comment about it is judging a book by its cover, and that is NOT a good habit to get into.
My account is nearing its finish.
It'll be great.
I promise.
- _nix
- Scratcher
1000+ posts
[Suggestion] The Label Block
that is NOT a good habit to get into.Ehh, I agree with your point that you made it grey, because you weren't sure what color works best. (I suggest control, since it controls the flow of the program, like “repeat” and “if” blocks.) But judging a block on how it looks does make sense a Also, just giving a first glance on the block and making a comment about it is judging a book by its cover, and bit, at least when you're doing it constructively. For example, I could tell you that it saying “label” doesn't make sense, because “label” is an ambiguous word. It could mean drawing text with the pen, or it could look like an in-script code comment; I think most people wouldn't guess that it means a place you can make the execution of the program jump to using a “jump to” block. Same deal with the “jump to” block – to most Scratch users, that would probably look like a block that animates the sprite jumping to a position! Which obviously is not the block that you're suggesting here.
So as we see, in this case, the block is a bit of a different style from other blocks; other blocks mostly have obvious meanings, but this one doesn't. Another difference between this block and most others – “label (my label)” is kind of like an embedded “when I receive block”. It doesn't do anything immediately, unlike every other stack block. The idea that a block doesn't immediately do anything at all might confuse users a bit.
══ trans autistic lesbian enbydoggirls // 16 17 18 19 20, she/they ════
sparrows one word to the paragraph // <3 // ~(quasar) nebula
- miniepicness
- Scratcher
1000+ posts
[Suggestion] The Label Block
I already suggested jumps
—————————–
-Click here to go to my profile —-Invited to scratch by AmazingProgrammer123
-Some Old Games: Racing Cats,Hungry Cat, Trapped, Mini-nation, ᴍAdvεnturᴇ﹗ and more!
- My“Any-Game”studio- All of My Projects/Games -My first project -my 200th project - handimation old shop:ACM-PICSHOP
click here for all my posts search the forums my first post :) my first thread/topic | click here
this signature is old⁽¹⁾
uV3b51yWZStHBjA8Lw7k
- goldfish678
- Scratcher
1000+ posts
[Suggestion] The Label Block
can you provide a forum thread link? I already suggested jumps
for the actual suggestion, this could be a nice feature. i've used it in batch before, and it makes things much easier in that context, but i wouldn't be entirely sure about scratch. as far as kids' programming languages go, this can be a pretty advanced control flow concept (i do agree that it would go under “control”), and i just don't know that it would work well with scratch's already existing control functions. i'd have to do further research, though.
- Discussion Forums
- » Suggestions
- » [Suggestion] The Label Block