Discuss Scratch

marshmallowop
Scratcher
42 posts

Two new control blocks: [Trigger "ID"] and ["ID" Name] to partially trigger script chains

Trigger ID:
This block allows to go to certain location of a script.
It activates the block “ID Name (Name)” of the same ID and such “ID Name (Name)” starts the activation of the blocks below such “ID Name (Name)”.
Trigger ID ["ID name"] :: control

ID Name:
If the ID name of this block match the ID of a Trigger ID block, and such Trigger ID is activated, this block is also activated.
ID Name ["ID name"] :: control
Note.1: It would not need an event running to start running by itself and the portion below after being activated by a Trigger ID block.
Note.2: All its duplicates starts to run when Trigger ID block activates such ID.
Note 3: This block alone has no action at all, and is ignored by the script, it is only triggered when the Trigger ID block activates these.
Note.4: This block only triggers once the next blocks under it, it deactivates until it is activated again by a “Trigger ID (Name)” block.


Example of how it would interact with the script structure:
(This example is about finding a treasure, which is a chest, note that there are other ways to get chests not mentioned in the example below).
(Also to note that the example below is just a segment).
when [space v] key pressed
wait until <not <key [space v] pressed?>>
if <(Shovel ) = [1]> then
Trigger ID [Found?] :: control
end

when I receive [Chest v]
move (10) steps
play sound [sound7 v]
wait (1) secs
ID Name [Tresure Found] :: control
switch costume to [costume 1 v]

ID Name [Found?] :: control
if <touching color [#F0D155] ?> then
wait (0.5) secs
say [Found a chest!]
Trigger ID [Tresure Found] :: control
change [brightness v] effect by (80)
wait (0.6) secs
set [brightness v] effect to (0)
end

In the example above, both of the scripts below the “when space key pressed” script are activated by such script in the next manner:
- The script chain “When I receive: chest” in this case starts at the location of the “ID Name (Name)” so only “switch costume to (costume 1)” is considered and triggered in this situation.
- The script chain “if touching color (color)” script even though it has no main event to trigger it, it do has the “ID Name (Name)” on it, so as this “ID Name (Name)” block is activated, all the blocks below starts to be triggered once (and be triggered again if “ID Name (Name)” is triggered once again by “Trigger ID (ID Name)”

In resume, these blocks purpose is to save time of the user by re-using already made scripts by triggering these partially by using these new control blocks.

Last edited by marshmallowop (April 11, 2022 16:49:32)

marshmallowop
Scratcher
42 posts

Two new control blocks: [Trigger "ID"] and ["ID" Name] to partially trigger script chains

Forgot to mention, if a “ID Name (Name)” is inside a inactive forever loop, this forever loop will not be triggered by it, only the items below such “ID Name (Name)” will be triggered.

The forever loop would only be activated by this “ID Name (Name)” in case such control block is above of such forever loop.

And in case the forever loop was already triggered (and the “ID Name (Name)” is inside of it), then the “ID Name (Name)” will pause the forever loop and run the scripts below it and then the forever loop will continue running from where it was paused.
______
Some changes/improvements:

Trigger ID potential change:
Could also have two options “Trigger and Stop”
Additionally when “stop” option is selected, it could display two additional options:
[Stop v] ID ["ID name"] [this v]:: control
- The first selector has two options: Trigger and Stop.
“Trigger”: Do what the OP says.
“Stop”: Instead stops blocks that are being triggered by the “ID Name (Name)” in that moment. So only a portion of such script chain is triggered.

- The second selector has two options: “this” and “all”
“This”: Only stops the “ID Name (exactly this name)” block that is being triggered in that chain, while all other duplicates continues to run uninterrupted.
“All”: This stops all the “ID Name (exactly this name)” block and duplicates that is being triggered with the same ID.

ID Name potential change:
ID Name ["ID name"]order[1] :: control
This second text after “order” could help to decide which ID Name is ran first, so if there is duplicates these would run in the order of its sequence number.

Example of stopping ID Name:

when [space v] key pressed
wait until <not <key [space v] pressed?>>
if <(Shovel ) = [1]> then
[Trigger v] ID [Found?] :: control
end

when I receive [Chest v]
move (10) steps
ID Name [Tresure Found] order[2]:: control
play sound [sound7 v]
[Stop v] ID [Tresure Found] [this v]:: control
wait (1) secs
ID Name [Tresure Found] order[1]:: control
switch costume to [costume 1 v]

ID Name [Found?] order[1] :: control
if <touching color [#F0D155] ?> then
wait (0.5) secs
say [Found a chest!]
[Trigger v] ID [Tresure Found] :: control
change [brightness v] effect by (80)
wait (0.6) secs
set [brightness v] effect to (0)
end

In the example above:
The when space key pressed chain:
It trigger Found? as in the OP.

In the When I receive Chest chain:
In this case when “ID Name (Treasure found)” is triggered, firstly the duplicate with number (1) is played first, only triggering “switch costume to (costume 1)”.
Then secondly, the duplicate with the number (2) is triggered, it plays all the blocks until meeting “Stop ID (Treasure Found)”, this stops all the triggering of the “ID Name (Treasure Found)” duplicates.

In the third block chain, it all works also like in the OP.

Sidenote.1: If there is two duplicates of “ID Name (Name) order (1)” then both would try run firstly.
Sidenote.2: In addition to save time, also the user save coding space and perhaps a more organized running sequence.

Last edited by marshmallowop (April 11, 2022 18:20:33)

watashiwanekodesu
New to Scratch
9 posts

Two new control blocks: [Trigger "ID"] and ["ID" Name] to partially trigger script chains

This seems a lot like the jump statements in assembly code…
Anyway, I like organization stuff, so I would support this if it were slightly more intuitive. However, it may be confusing for new Scratch users, and so is probably not the best idea for a new Scratch block.

define semicolon
set [n] to [1]
repeat until <not<C-style language>>
repeat (n)
compiletime_error;
end
change [n] by ((n)*(n))

Powered by DjangoBB