stonefish
stonefish

Reputation: 125

How to stop a clone from inheriting a message

I have this code:

code

But whenever the shoot message is sent to the bullet sprite, and there is a clone on the stage that hasn't hit it's target yet, the clone will be sent back with the go to x: (xOfTower) y: (yOfTower) block. Is there some way to prevent a clone from receiving a message while the real sprite does?

Upvotes: 4

Views: 1474

Answers (3)

call-me
call-me

Reputation: 726

Clones have their own copy of local variables!

To solve this problem you can add a new variable but be sure to check 'For this sprite only'. Otherwise there will only be 1 variable.

enter image description here

Now a new variable will be created for each clone. Give the variable a value to label it as clone and add a guard on your message action.

scratch code

Upvotes: 3

opetch18
opetch18

Reputation: 49

Yes there is. It has been a while since I have done Scratch but I remember that clones have variables, so if you give a clone a variable (something like: isClone) and then inside the messages it is inheriting have an if statement at the top so everything else runs if it is true. Then the if statement if set up correctly should check if isClone is equal to 0 and then if so then run the broadcast. The way you give clones variables is through inheritance because they inherit variables, if you change a variable inside a clone script then it will change the variable only for that clone and not the parent sprite or any other clone.

Upvotes: 1

Morag Hughson
Morag Hughson

Reputation: 7579

There is no way to prevent all sprites receiving the broadcast message. You have to write code to make those that shouldn't act on it, ignore it. In this case I suggest it is easier to do the following:

Suggest moving the two lines

point in direction (directionOfTower)
go to x: (xOfTower) y: (yOfTower)

into the when I start as clone block.

Upvotes: 1

Related Questions