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

#1 2009-09-09 15:07:28

Inori
Scratcher
Registered: 2009-09-09
Posts: 2

Can't understand what I'm doing wrong.

I'm pretty sure I'm missing something, but I can't figure out what it is.
It's a really simple code, self explanatory I guess:
http://img441.imageshack.us/img441/1885/whatt.gif
So what I need the code to do is to find a median out of 3 and just in case 2 or all of them are the same assign median to a certain one.

It all works well untill I set all 3 to one big number, for example 100, then switch one of the variables to x<100. After that the whole project seems to freeze. It will keep showing me x, no matter what numbers I choose on no matter what variable, even if I change all 3 of them to random numbers.

Offline

 

#2 2009-09-09 15:36:42

BoltBait
Scratcher
Registered: 2009-03-09
Posts: 1000+

Re: Can't understand what I'm doing wrong.

I would probably do it using a list variable, this way:

Delete all from templist
Add var1 to templist
if var2 > var1
  Add var2 to templist
else
  Insert var2 at 1 of templist
if var3 > item 2 of templist
  Add var3 to templist
else
  if var3 < item 1 of templist
    insert var3 at 1 of templist
  else
    insert var3 at 2 of templist

set med to item 2 of templist

Last edited by BoltBait (2009-09-09 15:45:10)


Animated sigs must be banned!
http://boltbait.com/j.pnghttp://boltbait.com/s.pnghttp://boltbait.com/d.pnghttp://boltbait.com/a.pnghttp://boltbait.com/p.png

Offline

 

#3 2009-09-13 14:57:46

Inori
Scratcher
Registered: 2009-09-09
Posts: 2

Re: Can't understand what I'm doing wrong.

BoltBait, a bit of a late reply from me, but I figured it's better late than never. It works! Thanks a lot!  smile

Offline

 

Board footer