This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-06-01 21:40:19

rivendell
Scratcher
Registered: 2007-05-29
Posts: 24

Touch sensing (or not) based on costume?

I'm making a game where a wizard's hat shoots monsters as they drop from the top of the screen: Wizards and Dragons.  When a monster gets zapped, the costume changes to a "burnt" monster and it falls off the screen.

I'd like to end the game if the wizard-hat gets hit by a monster... unless it's a "burnt" monster, in which case no harm done.

Any way to sense if a sprite is using a particular costume and take action based on that?

Offline

 

#2 2007-06-01 22:01:58

weissjd
Scratcher
Registered: 2007-05-16
Posts: 64

Re: Touch sensing (or not) based on costume?

Create a variable called burnt in your monster sprites. Make it for that sprite only and start it at zero. When the sprite gets burnt, set it to 1. Then when the sprite touches the had, check the value of the variable and only end the game if the variable is 1.

Offline

 

#3 2007-06-01 22:32:24

rivendell
Scratcher
Registered: 2007-05-29
Posts: 24

Re: Touch sensing (or not) based on costume?

weissjd, thanks... all I can say is, duh, why didn't I think of that?!

I guess what threw me off is that Scratch has a number of state variables (costume number, timer, etc.) that don't always give you both full read and write permission.  You can set the costume by number but you can't read that state back.  I just looked at the costume and thought, if I can set it, why can't I read it somehow?

The other reason is that your fix would require a big restructuring of my code.  My monsters detect themselves whether they have been hit by a bolt, so they can change their speed and appearance.  I had the wizard's hat detect if it had been hit to end the game, so that code didn't need to go into the (already complicated) monster scripts.  I guess I only have one of each monster on the screen at any time, so global variables might work without a big rewrite.

But I still want to be able to read the costume state as well as set it.  Thanks.

Last edited by rivendell (2007-06-01 22:38:29)

Offline

 

Board footer