Discuss Scratch

mnh78614
New Scratcher
17 posts

finding min and max?!?!

So I need help with another project for my comp sci class, so we have to find the min and max of two numbers
seems easy but we have to use a reporter function
so my code says:
<When green flag is clicked
ask “what is the first number”
set first number to answer
ask “what is the second number”
say maximum for 2 seconds>

then I made a reporter function for maximum which says;

<Maximum
script variable “return value”
if value 1 < value 2
set value 2 to return value
else
if value 1 > value 2
set value 1 to return value>

report “return value”
what did I do wrong?
michael42
Scratcher
26 posts

finding min and max?!?!

mnh78614 wrote:

if value 1 < value 2
set value 2 to return value
else
if value 1 > value 2
set value 1 to return value>

report “return value”
what did I do wrong?

Isn't the “set <variable> <newValue>” mixed up here?
ErnieParke
Scratcher
1000+ posts

finding min and max?!?!

michael42 wrote:

mnh78614 wrote:

if value 1 < value 2
set value 2 to return value
else
if value 1 > value 2
set value 1 to return value>

report “return value”
what did I do wrong?

Isn't the “set <variable> <newValue>” mixed up here?
Yep, you are correct. You need to set the return value to either value 1 or 2, not the other way around. So:

set [return value v] to [Whatever you return.]

With reassurances,

ErnieParke

Last edited by ErnieParke (Oct. 7, 2013 18:44:39)

mnh78614
New Scratcher
17 posts

finding min and max?!?!

so I made the changes, but for a response I'm getting zero! I need help this is due tonight!!
ErnieParke
Scratcher
1000+ posts

finding min and max?!?!

mnh78614 wrote:

so I made the changes, but for a response I'm getting zero! I need help this is due tonight!!
Okay, did you do your tests for min/max after you got your values?

With questions,

ErnieParke
scubajerry
Scratcher
1000+ posts

finding min and max?!?!

Can you share your project?
mnh78614
New Scratcher
17 posts

finding min and max?!?!


Here's the picture, I'm using a program called BYOB it's the same exact thing as stractch, the only difference is the sprite.
ErnieParke
Scratcher
1000+ posts

finding min and max?!?!

mnh78614 wrote:


Here's the picture, I'm using a program called BYOB it's the same exact thing as stractch, the only difference is the sprite.
Wait, aren't number1 and number2 supposed to be drop-down menus? I feel as if you're assigning the variable 0 what's really supposed to go into the two number vars, therefore ruining your project.

With questions,

ErnieParke
mnh78614
New Scratcher
17 posts

finding min and max?!?!

well i made that change, now variables “number 1” and “number 2” are drop downs. Still getting zero.
scubajerry
Scratcher
1000+ posts

finding min and max?!?!

mnh78614 wrote:


Here's the picture, I'm using a program called BYOB it's the same exact thing as stractch, the only difference is the sprite.
It is the exact same thing as stratch except where it is different (which appears to be a lot of places). From a syntax,

set (number 1) to (answer)  //scratch won't let you do this

set [number 1 v] to (answer) //it makes you do this

And I notice that that number 1 is a different color than the ones used in the IF. Is it really the same number 1?

Last edited by scubajerry (Oct. 8, 2013 01:13:04)

scubajerry
Scratcher
1000+ posts

finding min and max?!?!

We need a new picture
mnh78614
New Scratcher
17 posts

finding min and max?!?!

Yes I did that, still getting zero as an answer
scubajerry
Scratcher
1000+ posts

finding min and max?!?!

Need a new picture

Also, can you

 
say (return value) for [2] secs //at the end of the maximum function


if that doesn't tell you anything useful, say number 1 and number 2 at the start of the maximum function.
mnh78614
New Scratcher
17 posts

finding min and max?!?!

http://imageshack.us/f/14/pxd0.jpg/ new pic
scubajerry
Scratcher
1000+ posts

finding min and max?!?!

poof

Last edited by scubajerry (Oct. 8, 2013 01:36:45)

scubajerry
Scratcher
1000+ posts

finding min and max?!?!

You are setting number 1 twice
mnh78614
New Scratcher
17 posts

finding min and max?!?!

changed that, still getting zero as my return value!!!
scubajerry
Scratcher
1000+ posts

finding min and max?!?!

Need picture of both scripts and can you do the SAYs I mentioned earlier?

Last edited by scubajerry (Oct. 8, 2013 01:45:52)

mnh78614
New Scratcher
17 posts

finding min and max?!?!

Nvm fixed it somehow, now I need to do max of 3 numbers.
scubajerry
Scratcher
1000+ posts

finding min and max?!?!

OK - I will check back occasionally to see if you need any help.

Powered by DjangoBB