generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Distance between numbers.

Previous Thread :: Next Thread 
KEVEKEV77 is not online. 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 is not online. 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 is not online. morash
Joined: 22 May 2010
Total Posts: 5834
05 Jul 2015 09:16 PM
int, dec = math.modf(num)
Report Abuse
MrNicNac is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
05 Jul 2015 09:25 PM
do u understand now?
Report Abuse
morash is not online. 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 is not online. 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
LegitimatlyMe is not online. LegitimatlyMe
Joined: 30 Oct 2013
Total Posts: 1108
05 Jul 2015 09:29 PM
1.5 is 1/2 to 3, not 2/3
Report Abuse
BFFstick00 is not online. BFFstick00
Joined: 25 Oct 2010
Total Posts: 800
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 is not online. 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
BFFstick00 is not online. BFFstick00
Joined: 25 Oct 2010
Total Posts: 800
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 is not online. 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 is not online. 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 is not online. 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 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
05 Jul 2015 09:38 PM
thanks morash :3 works perfect
Report Abuse
BFFstick00 is not online. BFFstick00
Joined: 25 Oct 2010
Total Posts: 800
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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
05 Jul 2015 09:49 PM
LOL I ALMOST WENT OVERBOARD AND MADE A BINARY SEARCH FUNCTION FOR THIS
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image