Search code examples
mit-scratch

What do nested "touching" blocks do?


Making a Scratch platformer, I discovered that this did not work how I wanted:

enter image description here

...because it just didn't seem to run at the right rhythm for my program.

However, this did work:

enter image description here

...and I notice it being used in platformers such as Sushi Platformer.

Does anyone know what these nested touching blocks actually do?

Update:

@towerofnix is right... I made an experimental project, at https://scratch.mit.edu/projects/118349555/#player

...with the following experimental options:

enter image description here

Results:

Control: Platform detection works, but jitters up and down too much

Experiment1 (per @towerofnix): works, no jittering!

Experiment2: doesn't work, penguin goes down through floor sometimes

Experiment3: works, because it's equivalent to Experiment1!


Solution

  • Scratch isn't magic. It's a normal code interpreter (as far as I know).

    Now that that's out of the way, let's be the interpreter™ and figure this out.

    1. touching-color will return true or false.
    2. touching then takes the input true or false.
    3. touching will go through all sprites named true or false.
    4. since there are no sprites with those names (at least not in sushi platformer), just continue.
    5. next is return false, so return false.
    6. therefore the nest will always return false.
    7. not takes the input false, so it returns true.
    8. thus this - - is unnecessary and can be replaced with this -

    So if doing that last step doesn't result the same as not doing the last step, we really need to see your project!