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
you need to use broadcasts, or use veriables. it is hard to explain.
Offline
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
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!
Offline
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?
Offline
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!
Offline
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!
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.
Offline
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!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.
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
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
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