diddims4
|
  |
| Joined: 18 Feb 2010 |
| Total Posts: 884 |
|
|
| 09 Nov 2013 03:26 AM |
Say i have 16 number values.
how can i find the largest value of those 16 numbervalues?
|
|
|
| Report Abuse |
|
|
Zachiah
|
  |
| Joined: 27 Oct 2013 |
| Total Posts: 1401 |
|
|
| 09 Nov 2013 03:32 AM |
math.max
print(math.max(5,7,35,1,19,22,56,13,99,10,145,25,90,44,78,7)) |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2013 03:32 AM |
| print(math.max(1,40,2,42,124)) |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2013 03:33 AM |
Ninja'd
I found out about math.max after writing a function that did the same thing as it |
|
|
| Report Abuse |
|
|
diddims4
|
  |
| Joined: 18 Feb 2010 |
| Total Posts: 884 |
|
|
| 09 Nov 2013 03:49 AM |
How do i find out which value it is?
say
Value_One = 1 Value_Two = 3 Value_Three = 4 Value_Four = 5
etc.
local maxvalue = game.Workspace.Value_Four
in this case, how do i find the highest value? |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2013 03:56 AM |
| print(math.max(value_1, value_2, value_3)) |
|
|
| Report Abuse |
|
|
diddims4
|
  |
| Joined: 18 Feb 2010 |
| Total Posts: 884 |
|
|
| 09 Nov 2013 05:01 AM |
| wait, so will that print the number, or the value name? |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2013 05:07 AM |
The number I'll make you a function that returns the value name if you want |
|
|
| Report Abuse |
|
|
diddims4
|
  |
| Joined: 18 Feb 2010 |
| Total Posts: 884 |
|
| |
|
|
| 09 Nov 2013 05:36 AM |
Unless I misunderstood the question
function Most(...) MostTab = {...} Current = MostTab[1].Value for Index, Number in pairs(MostTab) do if Number.Value > Current then Current = Number.Value Answer = Number end end return Answer end |
|
|
| Report Abuse |
|
|
diddims4
|
  |
| Joined: 18 Feb 2010 |
| Total Posts: 884 |
|
|
| 09 Nov 2013 05:08 PM |
| What do i replace ... at function Most() ? |
|
|
| Report Abuse |
|
|
| |
|
diddims4
|
  |
| Joined: 18 Feb 2010 |
| Total Posts: 884 |
|
|
| 09 Nov 2013 05:37 PM |
| what about '...' at MostTab |
|
|
| Report Abuse |
|
|
Bebee2
|
  |
| Joined: 17 May 2009 |
| Total Posts: 3985 |
|
|
| 09 Nov 2013 05:40 PM |
... means it receives tuple arguments of infinite value.
Example
function lol(...) print(...) end
lol(1,2,3,4,5) lol(1,2,math.huge,'lol') |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2013 05:40 PM |
| You don't need to change anything about the function |
|
|
| Report Abuse |
|
|
diddims4
|
  |
| Joined: 18 Feb 2010 |
| Total Posts: 884 |
|
|
| 09 Nov 2013 05:49 PM |
| but then how do i put in my 16 values i want to check for the highest number? |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2013 05:50 PM |
| Most(Value_1, Value_2, Value_3 so on... Value_16) |
|
|
| Report Abuse |
|
|
diddims4
|
  |
| Joined: 18 Feb 2010 |
| Total Posts: 884 |
|
|
| 09 Nov 2013 06:26 PM |
ohhhhhhhhh, finally understand now! Ill try this and let you know if there are any errors |
|
|
| Report Abuse |
|
|
diddims4
|
  |
| Joined: 18 Feb 2010 |
| Total Posts: 884 |
|
|
| 14 Nov 2013 02:39 AM |
| Ok, so now how do i access 'Answer', outside of the function? |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 14 Nov 2013 02:56 AM |
| answer = Most(Value_1,Value_2,Value_3) |
|
|
| Report Abuse |
|
|
diddims4
|
  |
| Joined: 18 Feb 2010 |
| Total Posts: 884 |
|
|
| 15 Nov 2013 03:41 AM |
answer = Most(LapsDoneL1, LapsDoneL2, LapsDoneL3, LapsDoneL4, LapsDoneL5) wait(3) Message.Parent = game.Workspace Message.Text = "The winner of this round is... " wait(3) Message.Text = answer.Name .. "! If you are in " .. answer.Name .. ", then you get 5000 points!" print 'doesnt yet give points' wait(4) Message.Parent = nil
All variables are defined. Not working? THe part where it says answer.Name |
|
|
| Report Abuse |
|
|
diddims4
|
  |
| Joined: 18 Feb 2010 |
| Total Posts: 884 |
|
| |
|
diddims4
|
  |
| Joined: 18 Feb 2010 |
| Total Posts: 884 |
|
| |
|
|
| 16 Nov 2013 11:04 PM |
Just do this Values={}
print(math.max(unpack(Values))) |
|
|
| Report Abuse |
|
|
diddims4
|
  |
| Joined: 18 Feb 2010 |
| Total Posts: 884 |
|
|
| 16 Nov 2013 11:06 PM |
| Mind telling me what unpack does? |
|
|
| Report Abuse |
|
|