I made a project that sets the costume using variables, ie costume 1 is named 1, costume 2 is named 2 and so on until 3. A costume named 4 does not exist so when I tell it to go to costume 4 it just seems to go to some random costume. Is there any way to set a default costume that a sprite will use if it can't find the costume I want it to use?
Offline
An ambiguous situation can arise when costume names are numbers like "1", "2", "3" and you are also setting the costume using a variable. For example, if the third costume is named "2" and you do "switch to costume N" where N is a variable with the value "2", what should Scratch do? It could either switch to the second costume (thinking of the variable as an index) or the third costume (thinking of the variable as a name).
To avoid this, it's best for costume names to begin with letters, so they can't be confused with numbers. For example: "c1", "c2", "c3" would be fine.
In your specific case, I'd guess 4 is being considered an index. If you have fewer than four costumes, it is wrapping around. (For example, if you had three costumes, it would wrap around to the first costume.)
To answer your question: no, there's no way to set a default costume. If you are using a number to select the costume, you can write code to test if the number is between 1 and the number of costumes and switch to a default costume if it is not.
-- John
Last edited by johnm (2011-04-20 08:39:30)
Offline