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

#1 2012-10-30 17:51:56

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

How to find the biggest variable?

Okay, unlike most of my questions, this one isn't very confusing. I have six variables that should be equal to different numbers after I run the program I made. How can I make a program that will determine which variable is greatest without having to make a giant "if var1 is greater than var2..." script?
Thanks in advance!


http://www.blocks.scratchr.org/API.php?action=random&return=image&link1=http://i.imgur.com/O0efo.png&link2=http://i.imgur.com/B1KzK.png

Offline

 

#2 2012-10-30 17:54:41

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

Re: How to find the biggest variable?

Do you want to know which variable holds the largest value or which is the largest value?


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 2012-10-30 17:57:35

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

Re: How to find the biggest variable?

BoltBait wrote:

Do you want to know which variable holds the largest value or which is the largest value?

Isn't it the same thing?  hmm
Um, well, what I mean is: if

<(variable1) = [3]>
<(variable2) = [8]>
and
<(variable3) = [5]>
I want it to be able to tell me that variable2 is the biggest. The variables won't have set values at the start of the program, they are each assigned random values.  wink

Last edited by Zangooser (2012-10-30 17:57:51)


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/O0efo.png&amp;link2=http://i.imgur.com/B1KzK.png

Offline

 

#4 2012-10-30 18:01:22

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to find the biggest variable?

And if two of the variables have the same value, what would you like to happen?


http://i46.tinypic.com/35ismmc.png

Offline

 

#5 2012-10-30 18:10:18

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

Re: How to find the biggest variable?

ErnieParke wrote:

And if two of the variables have the same value, what would you like to happen?

I'm going to figure out how to make the program pick one of the variables randomly. First I have to get this sorted out.


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/O0efo.png&amp;link2=http://i.imgur.com/B1KzK.png

Offline

 

#6 2012-10-30 18:18:16

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to find the biggest variable?

Also, is there some way that you would be willing to use a list instead of six variables?

Last edited by ErnieParke (2012-10-30 18:18:48)


http://i46.tinypic.com/35ismmc.png

Offline

 

#7 2012-10-30 18:20:54

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

Re: How to find the biggest variable?

ErnieParke wrote:

Also, is there some way that you would be willing to use a list instead of six variables?

Erm, well.... I already used the variables in several different scripts that are necessary to the program, so omitting them would pretty much be an overhaul of the entire program XP


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/O0efo.png&amp;link2=http://i.imgur.com/B1KzK.png

Offline

 

#8 2012-10-30 18:26:24

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to find the biggest variable?

Oh, and one last question, what do you want done to the largest variable once you've figured out which one it is?


http://i46.tinypic.com/35ismmc.png

Offline

 

#9 2012-10-30 18:27:45

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

Re: How to find the biggest variable?

ErnieParke wrote:

Oh, and one last question, what do you want done to the largest variable once you've figured out which one it is?

It's just going to broadcast a message and tell the Stage to switch backgrounds. If I needed help with that, heh... I would advise myself to give up scripting forever.  tongue


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/O0efo.png&amp;link2=http://i.imgur.com/B1KzK.png

Offline

 

#10 2012-10-30 18:46:18

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to find the biggest variable?

Well then, make a new variable called (biggest #) and try this:

set [biggest # v] to (variable1)
if <(variable2) > (biggest #)>
 set [biggest # v] to (variable2)
end
if <(variable3) > (biggest #)>
 set [biggest # v] to (variable3)
end
if <(variable4) > (biggest #)>
 set [biggest # v] to (variable4)
end
if <(variable5) > (biggest #)>
 set [biggest # v] to (variable5)
end
if <(variable6) > (biggest #)>
 set [biggest # v] to (variable6)
end
Filler.//Biggest # should now be equal to the biggest variable.
I hope that this helps!


http://i46.tinypic.com/35ismmc.png

Offline

 

#11 2012-10-30 20:10:09

Zangooser
Scratcher
Registered: 2012-03-18
Posts: 1000+

Re: How to find the biggest variable?

ErnieParke wrote:

Well then, make a new variable called (biggest #) and try this:

(script omitted)

I hope that this helps!

It does! Thank you so much! :D


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/O0efo.png&amp;link2=http://i.imgur.com/B1KzK.png

Offline

 

#12 2012-10-30 20:15:01

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to find the biggest variable?

Zangooser wrote:

ErnieParke wrote:

Well then, make a new variable called (biggest #) and try this:

(script omitted)

I hope that this helps!

It does! Thank you so much! :D

Your welcome!


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer