This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-11-18 15:39:11

Dan01
Scratcher
Registered: 2008-06-11
Posts: 100+

Best way to script between multiple costumes

Whats the best way to switch between multiple costumes without having a long line of scripts.

This is what I use in most of my games:

<forever>
<if><key[ right ]pressed?>
<switch to costume[ 1 ]
<wait( 0.25 )secsc>
<if><key[ right ]pressed?>
<switch to costume[ 2 ]
<wait( 0.25 )secsc>
<end>
<end>
<end>

But this is a very long script, and lags up a lot of sprites, making it hard to edit the scripts.

The next best one i could think of is this:

<forever>
<if><key[ right ]pressed?>
<repeat until><( costume <=> 3 )>
<if><key[ right ]pressed?>
<next costume>
<wait( 0.25 )secsc>
<else>

<end>

But this has a lot of glitches in it. Any help would be great.

To make it clear, I am looking for a way to switch between costumes of a sprite, without having to create long scripts.


http://img3.imageshack.us/img3/4743/ubd6522wp8.png
http://img3.imageshack.us/img3/4667/ubd3758ox2.png

Offline

 

#2 2008-11-18 17:11:34

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Best way to script between multiple costumes

Look at the code in this project http://scratch.mit.edu/projects/archmage/291819

I see a lot of projects where it is obvious that the person spend hours just making the code for the costumes which is a huge waste of time. The code in my example I posted is perfect, so try to use it.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#3 2008-11-19 12:54:06

Dan01
Scratcher
Registered: 2008-06-11
Posts: 100+

Re: Best way to script between multiple costumes

archmage wrote:

Look at the code in this project http://scratch.mit.edu/projects/archmage/291819

I see a lot of projects where it is obvious that the person spend hours just making the code for the costumes which is a huge waste of time. The code in my example I posted is perfect, so try to use it.

Thanks! It worked great  big_smile

One thing I would say though. When using a stance with multiple costumes, for example running, you missed out a wait block. Atm you use this script for stances with multiple costumes:

<switch to costume[1]
<repeat(3)
<wait( 0.05 )secsc>
<next costume>
<end>

This will switch the other first costume, wait 0.05, next costume, wait 0.05, next, wait, next, next costume, as there isn't another wait after you have done the 3 repeats.

So it should look like this:

<switch to costume[1]
<repeat(3)
<wait( 0.05 )secsc>
<next costume>
<end>
<wait( 0.05 )secsc>


http://img3.imageshack.us/img3/4743/ubd6522wp8.png
http://img3.imageshack.us/img3/4667/ubd3758ox2.png

Offline

 

#4 2008-11-19 13:16:16

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Best way to script between multiple costumes

Dan01 wrote:

archmage wrote:

Look at the code in this project http://scratch.mit.edu/projects/archmage/291819

I see a lot of projects where it is obvious that the person spend hours just making the code for the costumes which is a huge waste of time. The code in my example I posted is perfect, so try to use it.

Thanks! It worked great  big_smile

One thing I would say though. When using a stance with multiple costumes, for example running, you missed out a wait block. Atm you use this script for stances with multiple costumes:

<switch to costume[1]
<repeat(3)
<wait( 0.05 )secsc>
<next costume>
<end>

This will switch the other first costume, wait 0.05, next costume, wait 0.05, next, wait, next, next costume, as there isn't another wait after you have done the 3 repeats.

So it should look like this:

<switch to costume[1]
<repeat(3)
<wait( 0.05 )secsc>
<next costume>
<end>
<wait( 0.05 )secsc>

I guess you are correct. I doesn't make a big difference though.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#5 2008-11-19 13:31:57

Dan01
Scratcher
Registered: 2008-06-11
Posts: 100+

Re: Best way to script between multiple costumes

archmage wrote:

Dan01 wrote:

archmage wrote:

Look at the code in this project http://scratch.mit.edu/projects/archmage/291819

I see a lot of projects where it is obvious that the person spend hours just making the code for the costumes which is a huge waste of time. The code in my example I posted is perfect, so try to use it.

Thanks! It worked great  big_smile

One thing I would say though. When using a stance with multiple costumes, for example running, you missed out a wait block. Atm you use this script for stances with multiple costumes:

<switch to costume[1]
<repeat(3)
<wait( 0.05 )secsc>
<next costume>
<end>

This will switch the other first costume, wait 0.05, next costume, wait 0.05, next, wait, next, next costume, as there isn't another wait after you have done the 3 repeats.

So it should look like this:

<switch to costume[1]
<repeat(3)
<wait( 0.05 )secsc>
<next costume>
<end>
<wait( 0.05 )secsc>

I guess you are correct. I doesn't make a big difference though.

Suppose not  tongue  Anyway, thanks for the help  big_smile


http://img3.imageshack.us/img3/4743/ubd6522wp8.png
http://img3.imageshack.us/img3/4667/ubd3758ox2.png

Offline

 

Board footer