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 » Scripting Helpers
Home Search
 

Re: No math.floor operation?

Previous Thread :: Next Thread 
PsychoBob is not online. 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 is not online. 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 is not online. zazw3
Joined: 05 Jul 2008
Total Posts: 1238
06 Aug 2011 06:48 PM
You ae using parenthersis right?
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
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 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
06 Aug 2011 06:50 PM
@crazy


floor(-1.3) -> -1.6
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
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 is not online. 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
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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