Setting Snap Costumes By Name?

Is it possible to set a snap costume by name/number?

The snap costume is set to a drop down menu.

I'm looking to do something if you type
"What animal would you like to see?" and the user types in CAT it would display the CAT costume.

The best I've found is

if (answer = cat) set costume to cat and just having a ton of if(answer = X) set costume to X

but I was wondering if there's a direct way to access the costume names where if you named the costumes appropriately, you can set the costume without a bunch of if statements.

Thank you!

You can drop a reporter into the set costume block

untitled script pic

The also works with costume numbers

untitled script pic (48)

This will switch to the second costume.

If you want to get real fancy, and verify if the costume exists, you can do a script like this.

untitled script pic (49)

If the costume does not exist, then the sprite will not switch costumes, but if the costume does exist, it will switch.

Can't you do

set costume to (answer)::looks

EDIT: I've been ninja'd

Thanks! I didn't realize you can drop a "join" block into the drop down to turn it essentially into a text block.

LOL also the name over rides the number. I did it for science. If you switch to 2 and the 4th costume is called "2" it will switch to the 4th costume. Not that you should do that because it's confusing but I has to check.

Thanks again! This is a game changer for my program.

hidden sprited don't show speech bubbles so you could replace the "say" block with a "ask" block

The say block was an example. I don't expect that block to actually be used.

tell (my [stage v]::sensing ) to ({say [costume doesn't exist]} @addInput::grey ring)::control

or even:
run (join [an error:·] [costume doesn't exist.] @delInput @addInput::operators)::control

huh? stage can say stuff? i always assumed you can't do that because in scratch you can't

It used to throw an error, but in a recent update, jens made the stage be able to use the say block.

There are many things you can do in Snap! but not in Scratch. :~)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.