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

#1 2010-03-05 14:18:22

fireballman
Scratcher
Registered: 2010-02-17
Posts: 14

Need help programming

I'm tryin to get the last 'if' statement to work but he either moves or jumps. How do I get it to work? example:
[blocks]<when green flag clicked>
<forever>
<if>
<key[ up arrow ]pressed?>
jump
<else>
<if>
<key[ right arrow ]pressed?>
move right
<else>
<if>
<key[  << up arrow <and> right arrow >>  ]pressed?>
front flip[/blocks]


There are only 10 types of people in the world: Those who know binary and those who don't.

Offline

 

#2 2010-03-05 14:48:00

Wolfie1996
Retired Community Moderator
Registered: 2009-07-08
Posts: 1000+

Re: Need help programming

Hi, fireballman!

Have you tried using the motion blocks? Maybe split your scripts up, too, that usually helps to show where things go wrong, and it makes things run faster  smile  Like so:
[blocks]
<when green flag clicked>
<forever>
<if><key[ up arrow ]pressed?>
<change y by( INSERT A NUMBER
     <if><key[ right arrow ]pressed?>
     <turn cw( INSERT A NUMBER )degrees>
<else>
<if><key[ right arrow ]pressed?>
<change x by( INSERT A NUMBER

[/blocks]

Hope this helps  smile


"...Jargon - the practice of never calling a spade a spade, when you might instead call it a manual earth-restructing implement..." - Bill Bryson, Mother Tongue

Offline

 

#3 2010-03-05 16:48:15

fireballman
Scratcher
Registered: 2010-02-17
Posts: 14

Re: Need help programming

Noooo I don't think you understand because of my terrible explanation. I got him to move using the motion blocks and jump using some kind of sin of sine script, but he doesn't front flip when you push right arrow AND up arrow. I have seperate front flip costumes that he is meant to switch to when you push up and right keys but he doesn't seem to switch to them.
Is it because the up and right arrow keys already make him do something different?


There are only 10 types of people in the world: Those who know binary and those who don't.

Offline

 

#4 2010-03-05 23:38:07

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: Need help programming

The way your script runs is as follows:
1) If the up arrow is pressed, he moves up.
2) If not, he sees if the right arrow is pressed, and it so, he moves right.
You see, he only checks for right/left IF the up arrow is NOT pressed.

A better way, in this case, would be:
<when green flag clicked>
<forever>
|<if><key[ up ]pressed?>
||Code to be executed if up key is pressed
|<end>
|<if><key[ left ]pressed?>
||Code to be executed if left key is pressed
|<end>
|<if><key[ right ]pressed?>
||Code to be executed if right key is pressed
|<end>
<end>


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

Board footer