Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How can I make the game sense different costumes?
- darface
-
32 posts
How can I make the game sense different costumes?
I am making a game where two samurai lunge at each other and the samurai with the better stance wins in a “Rock/Paper/Scissors” style fight. The samurai change stance by switching costumes, but I can only make the game recognize different sprites, not costumes.
Basically, I can't do this:
So if I tried to run the game, both samurai woul just kill each other no matter what.
What should I do?
Basically, I can't do this:
So if I tried to run the game, both samurai woul just kill each other no matter what.
What should I do?
- tiger75
-
100+ posts
How can I make the game sense different costumes?
Lets say costume 1 is “rock”
costume 2 is “paper”
I guess this would be how I do it, though it hasn't been tested, so…
costume 2 is “paper”
I guess this would be how I do it, though it hasn't been tested, so…
- Brontosplachna
-
100+ posts
How can I make the game sense different costumes?
Don't forget about this sensing block:
- BKFighter
-
1000+ posts
How can I make the game sense different costumes?
+1 Best answer. You could even use the backdrop scripts to detect both of them, which would probably easier, and broadcast to the sprites only tell them what animations and other minor stuff to do. Kinda like server-client relations, rather than peer-to-peer as suggested by tiger75 above. Don't forget about this sensing block:
- darface
-
32 posts
How can I make the game sense different costumes?
Why can't I do this? Don't forget about this sensing block:
It only lets me sense “costume name”…
- footsocktoe
-
1000+ posts
How can I make the game sense different costumes?
Why can't I do this? Don't forget about this sensing block:
It only lets me sense “costume name”…
If you just want to know what costume a particular sprite is wearing, then the query has to be in that sprite's script and use the variable
So what you do is in that sprite's script you set a global variable called “particular sprite's costume #” = to that sprite's costume #
And now all the other sprites know what costume that particular sprite is wearing.
Last edited by footsocktoe (Dec. 26, 2015 15:42:31)
- darface
-
32 posts
How can I make the game sense different costumes?
How do you do that? I don't know how to make a global variable.Why can't I do this? Don't forget about this sensing block:
It only lets me sense “costume name”…
If you just want to know what costume a particular sprite is wearing, then the query has to be in that sprite's script and use the variable
So what you do is in that sprite's script you set a global variable called “particular sprite's costume #” = to that sprite's costume #
And now all the other sprites know what costume that particular sprite is wearing.
- asivi
-
1000+ posts
How can I make the game sense different costumes?
Go to data create a new variable name it and tick for all sprites.
- footsocktoe
-
1000+ posts
How can I make the game sense different costumes?
Go to data create a new variable name it and tick for all sprites.
What asivi said…
GLOBAL = for all sprites
LOCAL = for this sprite only
- darface
-
32 posts
How can I make the game sense different costumes?
I wish I could show you my code blocks without painstakingly rewriting them here…can I?
Last edited by darface (Dec. 27, 2015 09:12:18)
- asivi
-
1000+ posts
How can I make the game sense different costumes?
You don't need the variable named “global variable”, the variable “HeroCostume” is currently a global for all sprites.
If you need to detect costumes of sprite AttemptChar2 just rename “global variable” to “EnemyCostume” or similar, and add in its scripts under the green flag the forever loop that updates continuously the number of costume.
Last edited by asivi (Dec. 27, 2015 11:23:30)
- darface
-
32 posts
How can I make the game sense different costumes?
Okay, now I tested the game and I messed up more than I thought.
1. The characters now simply phase through each other no matter what.
2. I wanted to randomize the enemy's attacks but instead it does them all at once.
What to do now?

1. The characters now simply phase through each other no matter what.
2. I wanted to randomize the enemy's attacks but instead it does them all at once.

What to do now?
- asivi
-
1000+ posts
How can I make the game sense different costumes?
1st delete the EnemyCostume variable, then create it again and be sure that you are selecting “for all sprites”.
Regards.
Regards.
Last edited by asivi (Dec. 27, 2015 15:22:26)
- footsocktoe
-
1000+ posts
How can I make the game sense different costumes?
To test whether a variable is global (for all sprites) or local (this sprite only) just create a new temporary sprite, look in it's data panel and see if the variable is there. If not, it was a local variable. If it is there, it's a global variable. Then delete the sprite.
- darface
-
32 posts
How can I make the game sense different costumes?
While the EnemyCostume variable now exists for all sprites, that didn't really help with the problems I listed above…
- deck26
-
1000+ posts
How can I make the game sense different costumes?
Get rid of duplicate scripts which are just confusing things. One script to control each sprite should be enough. Use the method mentioned earlier to detect the costume rather than using a wasteful forever loop to set a separate variable.
You don't need to worry about touching the costume of a sprite - you're either touching a sprite or you aren't. If the costume is important you need to check whether you're touching and which costume it has as separate things.
So
If the costume # is 7 the boolean expression will evaluate as true (or 1) and ‘Costume of True’ is meaningless so how can you detect touching it? If the costume # is not 7 you're trying to work out the ‘Costume of False’ which is also nonsense.
You can touch a sprite or the mouse pointer or the edge but nothing else will be detected using that block.
You don't need to worry about touching the costume of a sprite - you're either touching a sprite or you aren't. If the costume is important you need to check whether you're touching and which costume it has as separate things.
So
for example will firstly evaluate whether the costume number of the sprite running the script is number 7.
If the costume # is 7 the boolean expression will evaluate as true (or 1) and ‘Costume of True’ is meaningless so how can you detect touching it? If the costume # is not 7 you're trying to work out the ‘Costume of False’ which is also nonsense.
You can touch a sprite or the mouse pointer or the edge but nothing else will be detected using that block.
Last edited by deck26 (Dec. 28, 2015 15:41:15)
- darface
-
32 posts
How can I make the game sense different costumes?
I'm really confused. Can you give me a step-by-step on all of this? Get rid of duplicate scripts which are just confusing things. One script to control each sprite should be enough. Use the method mentioned earlier to detect the costume rather than using a wasteful forever loop to set a separate variable.
You don't need to worry about touching the costume of a sprite - you're either touching a sprite or you aren't. If the costume is important you need to check whether you're touching and which costume it has as separate things.
Sofor example will firstly evaluate whether the costume number of the sprite running the script is number 7.
If the costume # is 7 the boolean expression will evaluate as true (or 1) and ‘Costume of True’ is meaningless so how can you detect touching it? If the costume # is not 7 you're trying to work out the ‘Costume of False’ which is also nonsense.
You can touch a sprite or the mouse pointer or the edge but nothing else will be detected using that block.
- deck26
-
1000+ posts
How can I make the game sense different costumes?
As far as I can see you just want each sprite to choose a random costume and then compare them in some way. I'll assume costume 1 beats costume 2 but is beaten by costume 3 and that costume 2 beats costume 3. In its simplest form
The bit of the long if that you may not be able to see is checking if costume # of sprite2 is 1. Since costume 3 beats costume 1 we're checking for sprite1's costume being 3 and sprite2's costume being 1.
If you do that the controller script's broadcasts tell the sprites what to do assuming you've given the scripts to correspond with those broadcasts.
The bit of the long if that you may not be able to see is checking if costume # of sprite2 is 1. Since costume 3 beats costume 1 we're checking for sprite1's costume being 3 and sprite2's costume being 1.
Last edited by deck26 (Dec. 29, 2015 16:48:00)
- darface
-
32 posts
How can I make the game sense different costumes?
No, I only want the enemy sprite to choose a random attack (costume), while the player chooses one to counter it. As far as I can see you just want each sprite to choose a random costume and then compare them in some way.
- deck26
-
1000+ posts
How can I make the game sense different costumes?
OK, but that doesn't change things that much.No, I only want the enemy sprite to choose a random attack (costume), while the player chooses one to counter it. As far as I can see you just want each sprite to choose a random costume and then compare them in some way.
- Discussion Forums
- » Help with Scripts
-
» How can I make the game sense different costumes?