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

#1 2008-10-21 14:57:21

cheewowasmum
Scratcher
Registered: 2008-08-20
Posts: 5

This is probably easy but ...

My daughter 'cheewowa' wants to do a project where she has a load of different backgrounds and her sprites have a different conversation on each background. She likes to change backgrounds by pressing 'space' but how can she trigger the appropriate conversation for each background simply ? It's like we want to put different scripts on the sprites when they are on different backgrounds but are not sure how.

Offline

 

#2 2008-10-21 15:25:18

zawicki1fromyoutube
Scratcher
Registered: 2008-07-31
Posts: 1000+

Re: This is probably easy but ...

you need to use broadcasts, or use veriables. it is hard to explain.


|Call Of Duty: Black Ops Wii Friend Code: 3519-4456-0013|
|Follow me on Twitter|Subscribe To My Youtube Channel

Offline

 

#3 2008-10-21 16:42:15

Cyfarwyddyd
Scratcher
Registered: 2008-06-04
Posts: 17

Re: This is probably easy but ...

cheewowasmum wrote:

My daughter 'cheewowa' wants to do a project where she has a load of different backgrounds and her sprites have a different conversation on each background. She likes to change backgrounds by pressing 'space' but how can she trigger the appropriate conversation for each background simply ? It's like we want to put different scripts on the sprites when they are on different backgrounds but are not sure how.

that's a good question. one way to do it is to use if-then blocks based on the costume number of the stage, such as this simple project that you can use if it is helpful:

http://scratch.mit.edu/projects/Cyfarwyddyd/298341

Offline

 

#4 2008-10-21 16:45:53

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: This is probably easy but ...

One approach, as mentioned by zawicki(etc) above, would be to set up Broadcasts for each scene.  You could set it up so the broadcasts were triggered by the sprites or just have them set up to run from the keyboard.  Then, use the "When I Receive" block on the stage to set the correct background.  Also use the "When I Receive" block on each sprite that is going to talk.  Let me know if you want a demo made!


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#5 2008-10-21 18:51:34

zawicki1fromyoutube
Scratcher
Registered: 2008-07-31
Posts: 1000+

Re: This is probably easy but ...

Paddle2See wrote:

One approach, as mentioned by zawicki(etc) above, would be to set up Broadcasts for each scene.  You could set it up so the broadcasts were triggered by the sprites or just have them set up to run from the keyboard.  Then, use the "When I Receive" block on the stage to set the correct background.  Also use the "When I Receive" block on each sprite that is going to talk.  Let me know if you want a demo made!

So you agree with me?


|Call Of Duty: Black Ops Wii Friend Code: 3519-4456-0013|
|Follow me on Twitter|Subscribe To My Youtube Channel

Offline

 

#6 2008-10-21 19:45:44

matthewjose
Scratcher
Registered: 2008-07-16
Posts: 100+

Re: This is probably easy but ...

Do it like this:
On a sprite:
[blocks]                 <when green flag clicked>
                            <forever>
                            <if><key[ space ]pressed?>
                            <broadcast[ next background
                            <end>
                            <end>
On the background:
<when I receive[ next background
<next background>
Thanks, and Scratch on!  roll


My chat room, and join a Critique Group for feedback on your projects.

Offline

 

#7 2008-10-21 20:29:42

zawicki1fromyoutube
Scratcher
Registered: 2008-07-31
Posts: 1000+

Re: This is probably easy but ...

matthewjose wrote:

Do it like this:
On a sprite:
[blocks]                 <when green flag clicked>
                            <forever>
                            <if><key[ space ]pressed?>
                            <broadcast[ next background
                            <end>
                            <end>
On the background:
<when I receive[ next background
<next background>
Thanks, and Scratch on!  roll

that's not the best way to do it.
you should do:

<when green flag clicked>
<if> <key[ space ]pressed?>
<broadcast[ scene 2

<when I receive[ scene 2
<if> <key[ space ]pressed?>
<broadcast[ scene 3

and so on, and so forth.  lol


|Call Of Duty: Black Ops Wii Friend Code: 3519-4456-0013|
|Follow me on Twitter|Subscribe To My Youtube Channel

Offline

 

#8 2008-10-21 20:38:28

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: This is probably easy but ...

zawicki1fromyoutube wrote:

matthewjose wrote:

Do it like this:
On a sprite:
[blocks]                 <when green flag clicked>
                            <forever>
                            <if><key[ space ]pressed?>
                            <broadcast[ next background
                            <end>
                            <end>
On the background:
<when I receive[ next background
<next background>
Thanks, and Scratch on!  roll

that's not the best way to do it.
you should do:

<when green flag clicked>
<if> <key[ space ]pressed?>
<broadcast[ scene 2

<when I receive[ scene 2
<if> <key[ space ]pressed?>
<broadcast[ scene 3

and so on, and so forth.  lol

No, you need to do:
when green flag clicked
wait until key space pressed
broadcast scene 2

when I recieve scene 2
wait until key space pressed
broadcast scene 3

Offline

 

#9 2008-10-22 05:28:52

deerel
Scratcher
Registered: 2008-08-23
Posts: 89

Re: This is probably easy but ...

Well, how to do it most ellegantly? Maybe this is nice solution:

In stage:

<when green flag clicked>
<switch to costume[ first background
<broadcast[ act 1 ]and wait c>
<broadcast[ go to next act ]and wait c>
<broadcast[ act 2 ]and wait c>
<broadcast[ go to next act ]and wait c>
...
<broadcast[ act n ]and wait c>

<when I receive[ go to next act
<wait until><key[ space ]pressed?>
<next costume>

(of course, since this code is in Stage, the violet block are "switch to background" and "next background", but there are no icons for them, so I put the costume versions above)

In sprites:

<when I receive[ act x
... do whatever the sprite should do in act x, that is, move to appropriate position, change to appropriate costume, say/think, ...

And of course, feel free to use nice descriptive names like "intro", "on the beach", "the argument", etc. instead of dull "act 1", "act 2", ..., "act n" ;-)

The sprite can perform in this way, that is, it can say something, wait, move to another position, think/say something else, and so on. The space key will be blocked until the sprites play their act until the end, only after that it is possible to switch to next act, which is nice feature. Of course, if it is only: go to there and there and say this, then the space key is available immediately, but this solution opens the possibility that sprites may actually play the act. Hope it helped.

Last edited by deerel (2008-10-22 11:59:20)

Offline

 

#10 2008-10-22 14:20:59

cheewowasmum
Scratcher
Registered: 2008-08-20
Posts: 5

Re: This is probably easy but ...

Ooh thanks for all the help. I have checked out the example that Cyfarwyddyd posted using 'if then' as that is basically what cheewowa wants to do but I also like the example deerel suggested as that gives lots of scope.

Thanks everyone

Offline

 

Board footer