Post new topic    
Liquid Metal Slime
Send private message
Comparing Numbers in a Script 
 PostTue Oct 18, 2011 9:39 pm
Send private message Reply with quote
Hey guys,

Probably a silly question, but is there a simple way to check two numbers, find out which one is the smallest, and the result return that number (the smallest)?

If so, how would I go about doing it? I've look at value comparisons in the dictionary but I'm not sure what is the best way to go about it.
Cornbread Chemist
Metal King Slime
Send private message
 
 PostTue Oct 18, 2011 10:31 pm
Send private message Reply with quote
Use these:

Code:
script, min, a, b, begin
  if (a << b) then (return (a)) else (return (b))
end

script, max, a, b, begin
  if (a >> b) then (return (a)) else (return (b))
end
Super Slime
Send private message
 
 PostTue Oct 18, 2011 10:51 pm
Send private message Reply with quote
If TMC weren't such a wimp, he'd post versions of those functions that take more than two parameters

Angel
Mega Tact v1.1
Super Penguin Chef
Wizard Blocks
Liquid Metal Slime
Send private message
 
 PostWed Oct 19, 2011 7:54 pm
Send private message Reply with quote
Thanks, and it seems to work great. However, further on down the script I need to compare three numbers and once again picking out the smallest one to use. I've been beating my head against the wall trying to figure it out off and on today, so any help would be appreciated.
Cornbread Chemist
Metal Slime
Send private message
 
 PostWed Oct 19, 2011 7:59 pm
Send private message Reply with quote
Using TMC's scripts, for finding the smallest of three numbers you can use this:

min(min(a, b), c)

And so on, for however many numbers you want to compare.
Liquid Metal Slime
Send private message
 
 PostWed Oct 19, 2011 9:16 pm
Send private message Reply with quote
Thanks,

I didn't do it quite like that, but what I have right now seems to be working anyways.
Cornbread Chemist
Display posts from previous: