Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Switch costume to (Variable)?
- burroughszeb
-
New Scratcher
5 posts
Switch costume to (Variable)?
forever
switch costume to [() v]
end
So I was wondering if I could do something like this?
Where the variable determines the number of the costume.
If So why won't it work?
Please Help!!
- burroughszeb
-
New Scratcher
5 posts
Switch costume to (Variable)?
forever
switch costume to (Number)
stop [this script]
end
This is what my code looks like.
- nickwasp
-
Scratcher
100+ posts
Switch costume to (Variable)?
i don't know why you have the
you can do it like this

stop [this script v]
you can do it like this
forever
switch costume to (cos var)
end
broadcast [1+ v]
broadcast [1- v]Hope it helps!
when I receive [1+ v]
change [cos var v] by (1)
when I receive [1- v]
change [cos var v] by (-1)

Last edited by nickwasp (Sept. 13, 2015 22:38:43)
- burroughszeb
-
New Scratcher
5 posts
Switch costume to (Variable)?
This didn't really help
I need the stop variable. Trust me.
Anyways, I have a variable that changes 0-9
So that is why I wanted to know if I could link that with costumes.
I need the stop variable. Trust me.
Anyways, I have a variable that changes 0-9
So that is why I wanted to know if I could link that with costumes.
- Denciethepenguin
-
Scratcher
1000+ posts
Switch costume to (Variable)?
switch costume to (look at me I'm a variable :D)This makes it so that the costume changes to the variable. For example, if the variable is 6, it changes to the 6th costume. (If it's 0, it just changes to the last costume)
- burroughszeb
-
New Scratcher
5 posts
Switch costume to (Variable)?
When I did that it didn't work though.
- deck26
-
Scratcher
1000+ posts
Switch costume to (Variable)?
It should indeed work but do you have costume names which are numbers as that can confuse things - eg does switch to costume 3 mean the costume with name ‘3’ or the third one. I'd always use costume names starting with a character so eg
switch costume to (join [C] (variable))
- burroughszeb
-
New Scratcher
5 posts
Switch costume to (Variable)?
It should indeed work but do you have costume names which are numbers as that can confuse things - eg does switch to costume 3 mean the costume with name ‘3’ or the third one. I'd always use costume names starting with a character so egswitch costume to (join [C] (variable))
I do use numbers for costume names.
So you're saying if I use character names
it should work?
—–
Ok it did not work.
I named all my costumes “A” through “J”,
Put them in the order that I wanted them,
but nothing happened.
So I changed it back to the working version.
—–
Here is a link to my project, It's the “Panel” sprites that I am having trouble with.
They work with the current code, but I want it to be simplified.
https://scratch.mit.edu/projects/76610016/
- deck26
-
Scratcher
1000+ posts
Switch costume to (Variable)?
My point was not to have purely numeric costume names. My scripts would have coped with costumes called C1, C2 etc which is safer. If you're still having problems you need to share the project - as you've been told this should work so you're probably missing something that someone else might spot.
Edit - sorry, I see you have shared. The last paragraph looked like a signature so I ignored it!
Edit - sorry, I see you have shared. The last paragraph looked like a signature so I ignored it!
Last edited by deck26 (Sept. 14, 2015 12:33:11)
- deck26
-
Scratcher
1000+ posts
Switch costume to (Variable)?
So you're doing just what I was saying was a problem - you have, for Panel_1 the situation where the costume called 4 is actually costume number 2 and so on. That is asking for confusion. And at the start of the script for that sprite you set Number to false which doesn't match any of the ‘if’ statements.
If you want a 3 to appear it's much better to have a costume C3 which gives you that number. Then if a variable is set to 3 you can do the join I suggested to get costume C3 which matches. NB the costumes are C1, C2, C3 etc so the join can work - I'm NOT suggesting A1, B2, C3 etc.
If you want a 3 to appear it's much better to have a costume C3 which gives you that number. Then if a variable is set to 3 you can do the join I suggested to get costume C3 which matches. NB the costumes are C1, C2, C3 etc so the join can work - I'm NOT suggesting A1, B2, C3 etc.
- NilsTheBest
-
Scratcher
1000+ posts
Switch costume to (Variable)?
plz help how do you get the red blockWhat red block?
- Vicream_Creator
-
Scratcher
100+ posts
Switch costume to (Variable)?
plz help how do you get the red blockundefined block? By the way don't ask random questions on random posts, create your own one instead.
- deck26
-
Scratcher
1000+ posts
Switch costume to (Variable)?
Its not working for mePlease create your own new topic and share the project.
- -Rgames-
-
Scratcher
1 post
Switch costume to (Variable)?
I think you need to do it like this:
and then repeat that. That is what I'm having to do
forever
if <(foo) = [1]> then
switch costume to [1 v]
end
end
and then repeat that. That is what I'm having to do

- axisjack
-
Scratcher
100+ posts
Switch costume to (Variable)?
when I receive [switch custome]
switch costume to [foo]
Last edited by axisjack (March 10, 2019 08:33:55)
- deck26
-
Scratcher
1000+ posts
Switch costume to (Variable)?
Please don't necropost, this topic has been dealt with.
- Discussion Forums
- » Help with Scripts
-
» Switch costume to (Variable)?
