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

#1 2011-05-25 08:27:18

redman123
New Scratcher
Registered: 2011-05-18
Posts: 18

Need help with the script (up,down,left,right and jump

http://scratch.mit.edu/projects/redman123/1810674

I am still working on the movement of the main character. However, it seems that there is a giltch. When I press "right arrow" and "space", it will jump forward and land. While it reaches the ground , if I press left arrow I will jump backward immediately. Can anyone help me with the de-bug ? Or show me a better to re-program which has better result.


P.S The giltch doesn't happen when I jump left and press "right arrow" when it reaches the ground.

Offline

 

#2 2011-05-25 13:38:26

Flait7
Scratcher
Registered: 2008-04-14
Posts: 100+

Re: Need help with the script (up,down,left,right and jump

I think the glitch is in the Jumping script.  The script first checks to see if the right key's pressed to jump to the right, then after the script's finished jumping right it checks to see if the left key's pressed, and the sprite will jump if the left key's pressed at that time.

Maybe if you separated the scripts it wouldn't happen, for example, make two scripts that respond when you press space and use <if><<<key[ left arrow ]pressed?>  <and><<  <not> <key[ right arrow ]pressed?> >>  >>

and

<if><<<key[ right arrow ]pressed?>  <and><<  <not> <key[ left arrow ]pressed?> >>  >>

I think those would make sure that you can't press both at once and make a glitch, and that the person won't jump if you're pressing a key after landing....or you could use the glitch as a part of your game, and pretend that you did it on purpose?

Last edited by Flait7 (2011-05-25 13:45:30)


http://scratch.mit.edu/static/projects/Flait7/2248016_sm.pnghttp://scratch.mit.edu/static/projects/Flait7/1827934_sm.png

Offline

 

#3 2011-05-25 17:53:54

redman123
New Scratcher
Registered: 2011-05-18
Posts: 18

Re: Need help with the script (up,down,left,right and jump

thanks a lot , man. I have sloved my problem. By the way,
I noticed that when I kept holding down space bar [jump], the sprite would keeping jumping.  Is there a way that I can set the "jump" only works one time when I hold down the button and don't let go ? and when I release space bar and hit space bar again. the spite jumps ?

Offline

 

#4 2011-05-25 18:01:03

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Need help with the script (up,down,left,right and jump

Just use a "Wait until <not <key space pressed> >" block after the jump action, and it will wait for you to release the spacebar before you can jump again.


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

Board footer