For my I.T Homework I need to design a game. I am quite good with computers but new to scratch. I have designed my game but need a little help with the programming. I want a character to walk off the screen and change the stage background. I have a sprite called "wall" that when touched, will change the stage.
Here is my code so far:
<when green flag clicked>
<forever>
<if><touching[ Wall
Thank You,
Flashan
Offline
Flashan wrote:
For my I.T Homework I need to design a game. I am quite good with computers but new to scratch. I have designed my game but need a little help with the programming. I want a character to walk off the screen and change the stage background. I have a sprite called "wall" that when touched, will change the stage.
Here is my code so far:
<when green flag clicked>
<forever>
<if><touching[ Wall
Thank You,
Flashan
After
<when green flag clicked>
<forever>
<if><touching[ Wall
Try adding a broadcast block like this:
<broadcast[ change stage
The stage can then receive the message with
<when I receive[ change stage
<next costume>
Offline
or if there are different stages u need a swith to costume block. But it would work better if ur script is this
<when green flag clicked>
<wait until><touching[ wall
<broadcast[ switch
and then the stages script:
<when I receive[ switch
<switch to costume[ costume2
Last edited by bosox397 (2009-03-02 19:44:34)
Offline
refrain from broadcasts. Rather do something like
[blocks]
<when green flag clicked>
<forever>
<if><touching[ wall ]>
<set{ Background }to( 1 )
<end>
<end>
and then the stage's script:
<when green flag clicked>
<forever>
<switch to costume[ <{ Background }>
<end>
[/blocks]
this way, many diffrent broadcasts can be replaced by 1 variable
Last edited by yambanshee (2009-03-03 06:58:03)
Offline
No, none of these will work. The script does not wait until the sprite doesn't touch the edge of the screen, and goes on forever. Here is the correct way(with variables):
"Wall" Sprite: [blocks]
<when green flag clicked>
<forever>
<if><touching[ character ]>
<wait until> << <not> <touching[ wall ]> >>
<set{ bg }to( any )>
<end>
<end> [/blocks]
For "Character" Sprite:
<when green flag clicked>
<forever>
<if> <touching[ wall ]>
<go to x any )y any )>
<end>
<end>
For the Background: [blocks]
<when green flag clicked>
<forever>
<switch to costume[ <{ bg }> ]>
<end>
Last edited by Greatdane (2009-03-03 09:50:32)
Offline
Greatdane wrote:
No, none of these will work. The script does not wait until the sprite doesn't touch the edge of the screen, and goes on forever. Here is the correct way(with variables):
"Wall" Sprite: [blocks]
<when green flag clicked>
<forever>
<if><touching[ character ]>
<wait until> << <not> <touching[ wall ]> >>
<set{ bg }to( any )>
<end>
<end> [/blocks]
For "Character" Sprite:
<when green flag clicked>
<forever>
<if> <touching[ wall ]>
<go to x any )y any )>
<end>
<end>
For the Background: [blocks]
<when green flag clicked>
<forever>
<switch to costume[ <{ bg }> ]>
<end>
Why won't ours work? He just wants the background to change when a sprite touches the screen. I think that your method with variables is way better, but on the wall sprite, you said <wait until><< <not> <touching[ character >> .
Shouldn't it be << <not> <touching[ character >> ?
Anyways . . .
Offline
Oh, sorry. It's a long and complicated script, and everyone makes a few typos sometimes.
Last edited by Greatdane (2009-03-16 13:33:50)
Offline
And I guess I was thinking the wrong way... You are saying it does not switch to the NEXT background, but rather to A background.
Offline
Greatdane wrote:
No, none of these will work. The script does not wait until the sprite doesn't touch the edge of the screen, and goes on forever. Here is the correct way(with variables):
"Wall" Sprite: [blocks]
<when green flag clicked>
<forever>
<if><touching[ character ]>
<wait until> << <not> <touching[ wall ]> >>
<set{ bg }to( any )>
<end>
<end> [/blocks]
It'd be better as:
[blocks]
<when green flag clicked>
<forever>
<if><touching[ character ]>
<set{ bg }to( any )>
<wait until> << <not> <touching[ wall ]> >>
<end>
<end> [/blocks]
So it executes the code inmediately, but to execute it again, the player has to move and touch it again. Rather than waiting for the player to stop touching the wall to execute.
Offline