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

#1 2012-03-07 14:31:18

MightyMat
New Scratcher
Registered: 2012-02-10
Posts: 8

Short code tutorial for begginers:

This s only simple, nothing advanced...

To get a sprite to play a sound every 5 seconds, first upload that sound into the sprite, then insert the following code:

when gf clicked
forever
play sound [sound-name-here v]
wait [5]
end
Also, to make a sprite move when you press arrow keys, use this script:

when [right arrow v] key pressed
point in direction [90 v]
move [10] steps
end
when [left arrow v] key pressed
point in direction [-90 v]
move [10] steps
end
(note this only goes left and right, not up and down.)

If you want to make it jump you need a more advanced script, similar to this:

when [up arrow v] key pressed
change y by [10]
wait [0.1]
change y by [10]
wait [0.1]
change y by [10]
wait [0.1]
change y by [10]
wait [0.2]
change y by [-10]
wait [0.1]
change y by [-10]
wait [0.1]
change y by [-10]
wait [0.1]
change y by [-10]
end
This will make it jump more realisticly, but if you want a more simple yet less realistic jump, you can use this:

when [up arrow v] key pressed
change y by [40]
wait [0.2]
change y by [-40]
end
Hope this helped, if you make a project using this information, please reply with a link to it!

Offline

 

#2 2012-03-08 14:43:54

turkey3
Scratcher
Registered: 2011-12-04
Posts: 500+

Re: Short code tutorial for begginers:

MightyMat wrote:

This s only simple, nothing advanced...

To get a sprite to play a sound every 5 seconds, first upload that sound into the sprite, then insert the following code:

when gf clicked
forever
play sound [sound-name-here v]
wait [5]
end
Also, to make a sprite move when you press arrow keys, use this script:

when [right arrow v] key pressed
point in direction [90 v]
move [10] steps
end
when [left arrow v] key pressed
point in direction [-90 v]
move [10] steps
end
(note this only goes left and right, not up and down.)

If you want to make it jump you need a more advanced script, similar to this:

when [up arrow v] key pressed
change y by [10]
wait [0.1]
change y by [10]
wait [0.1]
change y by [10]
wait [0.1]
change y by [10]
wait [0.2]
change y by [-10]
wait [0.1]
change y by [-10]
wait [0.1]
change y by [-10]
wait [0.1]
change y by [-10]
end
This will make it jump more realisticly, but if you want a more simple yet less realistic jump, you can use this:

when [up arrow v] key pressed
change y by [40]
wait [0.2]
change y by [-40]
end
Hope this helped, if you make a project using this information, please reply with a link to it!

Don't listen to his advice on moving right. And left. It'll flip your sprite upside down do this:

To move right:

When gf clicked
Forever if <[right arrow] key pressed>
Change x by [3]
3 is just a random number. A higher number will move you faster.
If you want to move left make the 3 negative and change right arrow to left arrow

Offline

 

Board footer