I'm writing my first Snap! program, and I'm using the broadcast block to trigger an event with a second sprite. Is there any other way to coordinate events amongst sprites. Thanks!
Great question! There are a few ways you could go about doing this. You could create a global variable set to false as default. Once the event is triggered, you can change your variable to true. Within the sprites you can have a hat block saying something like "when [variable] is true".... and then runs your code.
Alternatively, you could create your own block that returns a boolean - and if that block returns true, your sprite can do a specific action. Hope this helps
You can use the tell block
Hi! Welcome to Snap!.
Maybe it'd help if you told us why you're looking for a different way. Why doesn't BROADCAST meet your needs?
P.S. As of the latest release of Snap!, you can direct a broadcast to a particular sprite. Click on the right arrowhead ︎ at the end of the block and it turns into
where the first slot is for the message and the second is for the sprite. Clicking the down arrowhead in that second slot gives you a menu of sprites.
when green flag clicked::control
set [var v] to <false::operators >
when <(var)=<true::operators >>:: control hat
Thanks for your help!
@bh Thanks for your helpful explanation of the new version of broadcast introduced in Snap! 8. I didn't have a particular reason for looking at other ways; I just always like to know about different options to accomplish a goal.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.