PsychoBob
|
  |
| Joined: 08 Jul 2009 |
| Total Posts: 11047 |
|
|
| 06 Aug 2011 06:47 PM |
| In order to make a "GetFactors" function for a little project I'm working on, I need access to the floor function. However when I do math.floor, it says that I'm attempting to call global floor, which ends up being a nil value. Why? |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 06 Aug 2011 06:47 PM |
Did anywhere in the script you declare a variable named math?
math=1; math="math"; math={}; |
|
|
| Report Abuse |
|
|
zazw3
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1238 |
|
|
| 06 Aug 2011 06:48 PM |
| You ae using parenthersis right? |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2011 06:49 PM |
Did you ever use "math" as a variable in your script? If so, that could overwrite the global math library.
If you can't figure out how to fix the problem, just use this instead of math.floor:
local function floor(arg) return arg - (arg%1); end
-Like a boss. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
| |
|
|
| 06 Aug 2011 06:53 PM |
local function abs(arg) return arg<0 and -arg or arg; end
local function floor(arg) return (abs(arg) - (arg%1)/(arg/abs(arg))); end
print(floor(-1.3)) --> 2
idc if it doesnt round towards 0 D:<
-Like a boss. |
|
|
| Report Abuse |
|
|
PsychoBob
|
  |
| Joined: 08 Jul 2009 |
| Total Posts: 11047 |
|
|
| 06 Aug 2011 06:54 PM |
I didn't declare math as a variable anywhere in any of my scripts.
What I don't get is how there's no math.floor operation for me even though it uses math.floor every time I use the modulo operator "%".
I'll just use math to isolate the floor operation from the modulo operator and see how that works. |
|
|
| Report Abuse |
|
|
zazw3
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1238 |
|
|
| 06 Aug 2011 06:54 PM |
| Guys we shouldent need to be re writing functions anyways just work out why the built in function isnt working for him! |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 06 Aug 2011 06:58 PM |
| modulus doesn't use math.floor()? It's a math operation, has nothing to do with math.floor. |
|
|
| Report Abuse |
|
|
PsychoBob
|
  |
| Joined: 08 Jul 2009 |
| Total Posts: 11047 |
|
|
| 06 Aug 2011 07:03 PM |
@SDuke
Directly from the lua manual,
a % b == a - math.floor(a/b)*b
I see a math.floor in there. |
|
|
| Report Abuse |
|
|
PsychoBob
|
  |
| Joined: 08 Jul 2009 |
| Total Posts: 11047 |
|
|
| 06 Aug 2011 07:11 PM |
Hey guys, help appreciated, but I fixed the problem.
The computer I was using conflicted with Roblox in some ways and did not update Roblox since I first downloaded it in 2009 - I redownloaded Roblox and the floor operation works now. Thanks! |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2011 07:11 PM |
@Psycho: That shows that they do the same thing, that doesn't show that one is how the other works.
-Like a boss. |
|
|
| Report Abuse |
|
|
PsychoBob
|
  |
| Joined: 08 Jul 2009 |
| Total Posts: 11047 |
|
|
| 06 Aug 2011 07:14 PM |
@crazypotato
At what point did I say that one of them was based off of the other? I don't recall saying that. |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2011 07:17 PM |
"it uses math.floor every time I use the modulo operator "%"."
"a % b == a - math.floor(a/b)*b
I see a math.floor in there."
You don't have to directly state something for it to be understood. It's obvious that you were trying to say that the operation a % b was done with that expression on the right side of the equation.
-Like a boss. |
|
|
| Report Abuse |
|
|