When I needed to change a variable within an operator block, I’d been removing the variable block and adding the right one. Unlike the “change <variable> …” and “set <variable>…” blocks, the little variable name bubbles do not have a drop-down selector. Today, Anya and I were working on our Chicken Keepers games and she right-clicked the little bubble to select a different variable. Totally didn’t realize you could do that.
While you can detect when a clone is touching a main sprite, there’s no way to detect if something is touching a clone. The workaround is to use broadcast messages to trigger events.
1. In the clone, create an “if touching” block to detect when it is being touched by the sprite
2. Within the if-touching block, send a broadcast message (under the “Events” blocks)
3. On the other sprite, create a block triggered by the “I receive” event for the code you want to run when this sprite touches the clone of another sprite.
4. Now a sprite executes the desired code when it is touching the clone of another sprite.
A few of the books I got for Anya are introductions to programming — Python, C++, and this GUI block-based system called Scratch. She likes using Python because Scott and I use it, but she absolutely adores Scratch. She has A Beginner’s Guide To Coding (Marc Scott) that I picked up from Book Outlet (I get a bonus 10$ when someone uses my referral link) for a couple of bucks. We’ve got a studio of our games online, and she’s excited to share the games with family members.
Tricks we’ve leaned so far:
- The UI will not match a book written a few years ago 🙂 This reminded me a bit of the “Internet Directory” book I had in 1994 … an obviously silly concept today, but a completely reasonable thing in 1994 when a decent bit of the content was still modem numbers. A book about a UI … it’s a good base — providing great first projects. But it took Anya a little while to accept that, while the book quite clearly told her to click an icon that looked like this … in the intervening 18-24 months, the UI had changed. How did I know this is what you click now? I mean, other than the fact it goes into the thing that has the same function as the one your book describes? A good guess!
- You can create variables with the same name. I am certain they are assigned some underlying UID that you never see, but if you have two variables named ‘score’ and the score doesn’t seem to be incrementing … look at your variable list.
- Variable scope of “this sprite” and “all sprites” is straight-forward until you create clones. “This sprite” means “this clone of a sprite”. We had a “all sprites” variable for speed and all of the clones will change speed each time a new clone pops in. This is cool if it’s what you want to do. I’ve also created variables scoped to “this sprite” to build clones that move at different speeds.
- You cannot, unfortunately, change a variable’s scope after you create it. You need to make a new one.
- The “glide” motion isn’t good for sensing collision. While the glide is in progress, that’s the block that is executing. Anya has a game where a crab collects crystals while avoiding divers which uses the fact you cannot check if Thing1 is touching Thing2. The grab can move through gliding divers with impunity. If you want to detect collisions, use a loop where the X and Y coordinates are changed in small increments instead of glide. Technically, there’s no collision detection while my X coordinate is changing, but that’s such a brief time interval that you cannot effectively avoid bumping into the other sprite while it moves.
- You can avoid the sprite being moved off of the screen to avoid collision by adding a bounce when the sprite is on the edge.
- You need to zero out your variables when the green flag is pressed, otherwise replaying the game by clicking the green flag again produces really strange behavior (you’ve already won or lost)
- Fractions can be used in places where they have integer examples. Specifically, you can pause for fractional seconds.
- When using clones, hide the “base” sprite that exists in the ‘when green flag clicked’ instantiation; use a ‘show’ in the ‘when I start as a clone’ block. Otherwise you have one sprite sitting at the edge of the screen
- “My Blocks” is used to build functions. In Anya’s Simon Says… game, we use the pseudorandom number generator to select “Simon’s” instructions and call a block based on the generated number.