Discuss Scratch

darface
New Scratcher
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:
touchingCostumeName?

So if I tried to run the game, both samurai woul just kill each other no matter what.

What should I do?
tiger75
Scratcher
100+ posts

How can I make the game sense different costumes?

Lets say costume 1 is “rock”
costume 2 is “paper”

ifcostume#=2 thenbroadcastpaperwhenIreceivePaperifcostume#=1 thensayPlayer "Paper" wins!for2secs

I guess this would be how I do it, though it hasn't been tested, so…
Brontosplachna
Scratcher
100+ posts

How can I make the game sense different costumes?


Don't forget about this sensing block:

costume nameof SomeOtherSprite


BKFighter
Scratcher
1000+ posts

How can I make the game sense different costumes?

Brontosplachna wrote:

Don't forget about this sensing block:

costume nameof SomeOtherSprite


+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.
darface
New Scratcher
32 posts

How can I make the game sense different costumes?

Brontosplachna wrote:

Don't forget about this sensing block:

costume nameof SomeOtherSprite


Why can't I do this?

EnemyPose1of EnemySprite

It only lets me sense “costume name”…
footsocktoe
Scratcher
1000+ posts

How can I make the game sense different costumes?

darface wrote:

Brontosplachna wrote:

Don't forget about this sensing block:

costume nameof SomeOtherSprite


Why can't I do this?

EnemyPose1of EnemySprite

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
costume#

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
New Scratcher
32 posts

How can I make the game sense different costumes?

footsocktoe wrote:

darface wrote:

Brontosplachna wrote:

Don't forget about this sensing block:

costume nameof SomeOtherSprite


Why can't I do this?

EnemyPose1of EnemySprite

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
costume#

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.

How do you do that? I don't know how to make a global variable.
asivi
Scratcher
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
Scratcher
1000+ posts

How can I make the game sense different costumes?

asivi wrote:

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
New Scratcher
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
Scratcher
1000+ posts

How can I make the game sense different costumes?

whenclickedswitchcostumetoAttemptChargotox:-163y:-39foreversetHeroCostumetocostume#whendown arrowkeypressedswitchcostumetoHeroPose1playsound223169__yoyodaman234__grass-footstep-4wait1secsswitchcostumetoHeroJump1playsound269311__kwahmah-02__swoosh08glide2secstox:-15y:84switchcostumetoHeroSwing1glide1secstox:164y:-39switchcostumetoHeroPose1iftouchingAttemptChar2?theniftouchingglobal variableofcostume#=1/pickrandom5to7?thenplaysound209101__lukesharples__tissue-slice-wound10glide1secstox:164y:-39switchcostumetoHeroPose1elseiftouchingcostume nameofcostume#=10?thenswitchcostumetoHeroDead1glide1secstox:-218y:-180elseiftouchingHeroCostumeofcostume#=2?thenswitchcostumetoHeroPose1glide1secstox:-185y:-39whenup arrowkeypressedswitchcostumetoHeroPose3playsound223169__yoyodaman234__grass-footstep-4wait1secsswitchcostumetoHeroJump3playsound269311__kwahmah-02__swoosh08glide2secstox:-15y:84switchcostumetoHeroSwing2glide1secstox:164y:-32switchcostumetoHeroPose3iftouchingAttemptChar2?theniftouchingglobal variableofcostume#=pickrandom1to4?thenplaysound209101__lukesharples__tissue-slice-wound10glide1secstox:164y:-39switchcostumetoHeroPose1elseiftouchingcostume nameofcostume#=7?thenswitchcostumetoHeroDead1glide1secstox:-218y:-180elseiftouchingHeroCostumeofcostume#=8?thenswitchcostumetoHeroPose1glide1secstox:-185y:-39whenright arrowkeypressedswitchcostumetoHeroPose2playsound223169__yoyodaman234__grass-footstep-4wait1secsswitchcostumetoHeroJump2playsound269311__kwahmah-02__swoosh08glide2secstox:-15y:84switchcostumetoHeroStab1glide1secstox:164y:-39switchcostumetoHeroPose2iftouchingAttemptChar2?theniftouchingglobal variableofcostume#=pickrandom1/8to10?thenplaysound209101__lukesharples__tissue-slice-wound10glide1secstox:164y:-39switchcostumetoHeroPose1elseiftouchingglobal variableofcostume#=4?thenswitchcostumetoHeroDead1glide1secstox:-218y:-180elseiftouchingHeroCostumeofcostume#=5?thenswitchcostumetoHeroPose1glide1secstox:-185y:-39

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
New Scratcher
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?
asivi
Scratcher
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.

Last edited by asivi (Dec. 27, 2015 15:22:26)

footsocktoe
Scratcher
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
New Scratcher
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
Scratcher
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

touchingCostumeofcostume#= 7? is meaningless
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
New Scratcher
32 posts

How can I make the game sense different costumes?

deck26 wrote:

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

touchingCostumeofcostume#= 7? is meaningless
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.
I'm really confused. Can you give me a step-by-step on all of this?
deck26
Scratcher
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

broadcastset-costumesandwait this script ensures both sprites are done before comparingifcostume #ofsprite1=costume #ofsprite2thenbroadcastdrawelseifcostume #ofsprite2-costume #ofsprite1=1 orcostume #ofsprite1=3 andcostume #ofsprite2=1 thenbroadcastsp1-winselsebroadcastsp2-winswhenIreceiveset-costumes each sprite does thisswitchcostumeto(pick random (1) to (3)) assuming 3 costumes
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
New Scratcher
32 posts

How can I make the game sense different costumes?

deck26 wrote:

As far as I can see you just want each sprite to choose a random costume and then compare them in some way.
No, I only want the enemy sprite to choose a random attack (costume), while the player chooses one to counter it.
deck26
Scratcher
1000+ posts

How can I make the game sense different costumes?

darface wrote:

deck26 wrote:

As far as I can see you just want each sprite to choose a random costume and then compare them in some way.
No, I only want the enemy sprite to choose a random attack (costume), while the player chooses one to counter it.
OK, but that doesn't change things that much.

Powered by DjangoBB