Discuss Scratch
- Discussion Forums
- » Questions about Scratch
- » Reasoning With The If Then Blocks
- mepomepo
-
Scratcher
84 posts
Reasoning With The If Then Blocks
There is no reasoning with scratch, or the If then blocks.
Example of an if then block:
but here is 3 questions:
what are the if then blocks?
why did the ST make them?
why are they here?
But here is the BIG question:
What in the world is without the if then blocks, and why, why, do they even mostly used?
Example of an if then block:
if <> then
end
but here is 3 questions:
what are the if then blocks?
why did the ST make them?
why are they here?
But here is the BIG question:
What in the world is without the if then blocks, and why, why, do they even mostly used?
Last edited by mepomepo (May 29, 2022 05:12:06)
- -EmeraldThunder-
-
Scratcher
1000+ posts
Reasoning With The If Then Blocks
The if then blocks are so your code can make decisions based on inputs or other data. If these blocks weren't in scratch, then it would certainly be a lot harder to create code with non-static outputs.
- mepomepo
-
Scratcher
84 posts
Reasoning With The If Then Blocks
The if then blocks are so your code can make decisions based on inputs or other data. If these blocks weren't in scratch, then it would certainly be a lot harder to create code with non-static outputs.Well, sometimes they are compared with the wait until blocks.
ex of wait until block:
wait until <>
- -EmeraldThunder-
-
Scratcher
1000+ posts
Reasoning With The If Then Blocks
(#3)Sometimes, the if block can be used in situations the wait until <> block can't.The if then blocks are so your code can make decisions based on inputs or other data. If these blocks weren't in scratch, then it would certainly be a lot harder to create code with non-static outputs.Well, sometimes they are compared with the wait until blocks.
ex of wait until block:wait until <>
For example, if you need to evaluate a position of an object in a single frame and then run a script immediately afterwards using a wait until <> block might hang the entire engine on the frame if the position is not correct.
Plus, the wait block has an internal if statement.
const condition = Cast.toBoolean(args.CONDITION); if (!condition) { util.yield(); }
- Za-Chary
-
Scratcher
1000+ posts
Reasoning With The If Then Blocks
The Scratch Team made the “if then” blocks because they are a basic thing in many other programming languages, including the text-based ones. @-EmeraldThunder- effectively describes what they do.
Here is an example for why “wait until” would not work. Suppose you want to make a character jump by pressing the up arrow key, but only if the space bar is being held down for some reason. Your two options are this:
The first option will have the desired outcome: when the up arrow key is pressed, the character will jump as long as the space key is being held down.
However, the second one doesn't work. If you use the second one, you could press the up arrow key without holding down the space bar, wait 5 minutes while you get a coffee or something, then press the space bar, and the character will jump. This is not the intended behavior.
Here is an example for why “wait until” would not work. Suppose you want to make a character jump by pressing the up arrow key, but only if the space bar is being held down for some reason. Your two options are this:
when [up arrow v] key pressed
if <key [space v] pressed?> then
jump
end
when [up arrow v] key pressed
wait until <key [space v] pressed?>
jump
The first option will have the desired outcome: when the up arrow key is pressed, the character will jump as long as the space key is being held down.
However, the second one doesn't work. If you use the second one, you could press the up arrow key without holding down the space bar, wait 5 minutes while you get a coffee or something, then press the space bar, and the character will jump. This is not the intended behavior.
- musicROCKS013
-
Scratcher
1000+ posts
Reasoning With The If Then Blocks
Yes. But remember, if you don’t put anything in the if then block, none of the code in it will run. You have to put one of those “< >” Boolean blocks in it to make it able to run. The if then blocks are arguably the most important block in scratch, although by themselves they are useless.
- d_over_dx
-
Scratcher
35 posts
Reasoning With The If Then Blocks
bruh this is stupid dont ask
SCRATCH is to get a SENSE of programming languages, not to make it HARD.
when green flag clickedor will you use:
forever
if <some condition> then
...
end
end
when green flag clickedand plus this is the main use of the if block.
wait until <some condition>
...
SCRATCH is to get a SENSE of programming languages, not to make it HARD.
- popjam12
-
Scratcher
500+ posts
Reasoning With The If Then Blocks
-snip-Yep. That's the answer really.
Last edited by popjam12 (May 29, 2022 19:56:17)
- d_over_dx
-
Scratcher
35 posts
Reasoning With The If Then Blocks
if block in most of the languages i know:
Python:
JS (JavaScript):
Python:
if condition: do_something()
if condition { do_something() }
- d_over_dx
-
Scratcher
35 posts
Reasoning With The If Then Blocks
if block in most of the languages i know:and, so:
Python:JS (JavaScript):if condition: do_something()if condition { do_something() }
“if” is important. my final statement.
- Discussion Forums
- » Questions about Scratch
-
» Reasoning With The If Then Blocks