KEVEKEV77
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 6961 |
|
|
| 05 Jul 2015 09:13 PM |
Kind of like on a number line.
anyways, I want a function that gives a decimal for a number... sorry explained that bad.. heres an example.
function wow(least,max,num) return calculations and such end
print(wow(1,3,1.5)
It would print .5
Another example:
print(wow(2,3,3) it would print 1
Please help me its so simple but i cant get it |
|
|
| Report Abuse |
|
|
naknak
|
  |
| Joined: 30 Jun 2008 |
| Total Posts: 350 |
|
|
| 05 Jul 2015 09:16 PM |
function wow(least,max)
--what are you literally trying to do? num = least-max
return num
end
I haven't messed with lua in a while and this is my first time back, but that is generally right. And if I am wrong someone correct me; like I said I haven't been back in a while. |
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
| |
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 05 Jul 2015 09:17 PM |
Your function parameters don't make sense. What is "max?"
Here's the way to do it, though:
function DistanceBetween(N1, N2) return(math.max(N1,N2) - math.min(N1,N2)) end |
|
|
| Report Abuse |
|
|
KEVEKEV77
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 6961 |
|
|
| 05 Jul 2015 09:18 PM |
thats not it, you left out third argument, which is important.
now read the post |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 05 Jul 2015 09:18 PM |
"thats not it, you left out third argument, which is important."
Because I don't understand what it is >.>
Read my post |
|
|
| Report Abuse |
|
|
KEVEKEV77
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 6961 |
|
|
| 05 Jul 2015 09:19 PM |
Ok sry lemme explain
There is three numbers,
1 3
those two are the outside ones.
1 1.5 3
The middle one is what im focusing on
Its .5 away
see?
.5 between the two numbers |
|
|
| Report Abuse |
|
|
naknak
|
  |
| Joined: 30 Jun 2008 |
| Total Posts: 350 |
|
|
| 05 Jul 2015 09:19 PM |
| You want the distance "num" is from "min" as well as "max?" |
|
|
| Report Abuse |
|
|
KEVEKEV77
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 6961 |
|
|
| 05 Jul 2015 09:20 PM |
sry mrnicnac, wasnt talking to u
but i dont think urs is what i want either 3: |
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 05 Jul 2015 09:23 PM |
| Yea, the original post made no sense. Your asking for the distance between numbers, which would be what MrNicNac posted or math.abs(N1 - N2), but then you say something about the decimal of a number, which what I posted answers. But then you give examples that nobody understands because they really don't fit either question. |
|
|
| Report Abuse |
|
|
KEVEKEV77
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 6961 |
|
| |
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 05 Jul 2015 09:25 PM |
"those two are the outside ones.
1 1.5 3
The middle one is what im focusing on
Its .5 away
see?
.5 between the two numbers"
Not really. It's .5 from 1, and 1.5 from 3. You would need two results, not one. |
|
|
| Report Abuse |
|
|
KEVEKEV77
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 6961 |
|
|
| 05 Jul 2015 09:27 PM |
no..... um..... like......
its halfway to both of them
so it its 2, it would be 2/3 to the max..
|
|
|
| Report Abuse |
|
|
| |
|
|
| 05 Jul 2015 09:29 PM |
| That my good friend is called subtraction. Biggest number - smallest number = middle. For multiple use (A+B+C+etc./number of numbers). That is called averaging. |
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 05 Jul 2015 09:30 PM |
But 1.5 is not halfway between 1 and 3. If you want the percent between you would use:
(num - min)/(max - min) |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2015 09:31 PM |
function myaverage(numbers) local sum = 0 for i, v in pairs(numbers) do sum = sum + v end return sum / #sum end |
|
|
| Report Abuse |
|
|
KEVEKEV77
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 6961 |
|
|
| 05 Jul 2015 09:33 PM |
so how do i get the function going
1---------1.5----------2
>1/2
6------9-----12 >1/2
1---------5----------10 >1/2
10--------------------20-20 >1
3--------9--12 > 2/3
|
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 05 Jul 2015 09:34 PM |
| (num - min)/(max - min) will return the percent between. |
|
|
| Report Abuse |
|
|
KEVEKEV77
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 6961 |
|
|
| 05 Jul 2015 09:36 PM |
| Workspace.Script:8: attempt to get length of local 'sum' (a number value |
|
|
| Report Abuse |
|
|
KEVEKEV77
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 6961 |
|
|
| 05 Jul 2015 09:38 PM |
| thanks morash :3 works perfect |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2015 09:41 PM |
I fixed the script I did it in literally 5 minutes.
function myaverage(numbers) local sum = 0 for i, v in pairs(numbers) do sum = sum + v end return sum / #numbers end |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2015 09:49 PM |
| LOL I ALMOST WENT OVERBOARD AND MADE A BINARY SEARCH FUNCTION FOR THIS |
|
|
| Report Abuse |
|
|