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

#1 2013-03-30 08:07:02

walkalone666
New Scratcher
Registered: 2013-03-30
Posts: 8

help please

i've been given this to program in but i cant o it to save my life



Place the sprite at x:0 and y:170
So long as the y position of sprite is greater than or equals to -175 it should move down the stage in 1 step intervals.

To my mind if the sprite's y position is equal to -175 it should continue to move and end up at -176.

Later on i am told that the sprite should not exceed -175

How can the sprite be equal to -175 and still move 1 place down but not exceed -175.

Offline

 

#2 2013-03-30 11:11:04

shivadas
Scratcher
Registered: 2010-02-06
Posts: 100+

Re: help please

It can't move down from -175 and still not exceed -175. Minus that part, the script would look like this:

when gf clicked
go to x: [0] y: [170]
forever if <<(y position) > [-175]> or <(y position) = [-175] >>
change x by [-1]
wait [0.01] secs
end
I always use the wait block when I am animating something or moving a sprite because otherwise it looks like it just jumps from place to place instead of actually moving there.

Hope that helps, and welcome to scratch!

Last edited by shivadas (2013-03-30 21:35:41)


Please check out my latest project, Hunger Avenger!

Offline

 

#3 2013-03-30 11:29:29

xlk
Scratcher
Registered: 2013-03-18
Posts: 57

Re: help please

no need for the

wait [0.01] secs
, the forever if already has a one screen delay, unless you want choppy movement...

Offline

 

#4 2013-03-30 13:15:15

walkalone666
New Scratcher
Registered: 2013-03-30
Posts: 8

Re: help please

still cant get it to work

Offline

 

#5 2013-03-30 14:21:40

xlk
Scratcher
Registered: 2013-03-18
Posts: 57

Re: help please

the "not exceed" part dosen't make sense. What do you want it to do, drop off screen?
I so:

when gf clicked
go to x: [0] y: [170]
repeat until <(y position) < [-175]>
 change y by [-1]
end

Offline

 

#6 2013-03-30 15:17:13

cauzality
New Scratcher
Registered: 2013-03-19
Posts: 44

Re: help please

when you fall by more than 1 pixel per step, you have the possibility of overshooting -175; in that case, you would use an "if else" statement to set it back:

when gf clicked
go to x: [0] y: [170]
set [falling speed v] to [-1]
forever
if < (y position) > [-175]>
   change y by (falling speed)
else
   set y to [-175]
end

Offline

 

#7 2013-03-30 21:22:23

xlk
Scratcher
Registered: 2013-03-18
Posts: 57

Re: help please

you just used a variable for no reason...
that would only be usefull to simulate gravity, if you added a "change falling speed by -1" block.
Still, he did say 1 step intervals, so why bother about overshooting?

Offline

 

#8 2013-03-31 00:34:22

cauzality
New Scratcher
Registered: 2013-03-19
Posts: 44

Re: help please

xlk wrote:

you just used a variable for no reason...
that would only be usefull to simulate gravity, if you added a "change falling speed by -1" block.
Still, he did say 1 step intervals, so why bother about overshooting?

sorry... i'm new here and am learning about the forum by trying it out. have mercy.

i had a couple reasons for the variable but i was probably directing my statements at the people who said the "do not exceed" instruction didn't make sense and less to the original question (i probably should have made that more clear).

i used it because variables can vary, even when they don't. so though it does nothing, it suggests a lot: it suggests other cases for which the variable takes other values (which is what i was trying to point out). i figured this was probably an early assignment (on simplistic gravity) and that more would follow (on realistic gravity).

i probably should have thought twice about that.

Offline

 

#9 2013-04-29 16:44:56

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: help please

If this question is about a homework assignment for a class - please make sure that asking for help on the Scratch forums doesn't violate any agreements you have with the teaching institution.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

Board footer