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
 

math.abs

Previous Thread :: Next Thread 
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
13 May 2014 08:47 PM
This will do the same thing as math.abs right?

function abs(...)
x = tonumber(select(1, unpack({...})))
if x then
return ((x ^ 2) ^ 0.5)
else
print("math.abs expected number, returning nil")
return nil
end
end
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
13 May 2014 08:52 PM
I don't think tonumber would return extra arguments to their number form.


Ex.

print(tonumber(unpack{1,8,'a','c'}))
Report Abuse
VehicleSim is not online. VehicleSim
Joined: 25 Jul 2013
Total Posts: 62
13 May 2014 08:57 PM
wtf

No more pickles, its all ogre now.
Report Abuse
Prescience is not online. Prescience
Joined: 26 Apr 2014
Total Posts: 188
13 May 2014 08:58 PM
veihcleSim, please do not post spam.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
14 May 2014 12:59 AM
tonumber only accepts 1 argument
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
14 May 2014 12:59 AM
And no, 128, that wouldn't.

here's a basic math.abs if you care
if x < 0 then x = -x end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
14 May 2014 01:06 AM
Well technically it accepts infinite arguments but ignores everything after the first
Report Abuse
smiley599 is not online. smiley599
Joined: 23 Jan 2010
Total Posts: 21869
14 May 2014 01:53 AM
print(smiley599.abs)
>6
Report Abuse
Nyxis is not online. Nyxis
Joined: 15 Nov 2012
Total Posts: 3374
14 May 2014 01:58 AM
'abs' is not a valid member of smiley599

unless its an external value, plus 'smiley599' is undefined.

lel
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
14 May 2014 02:02 AM
Nah, st0ff is variable hidden in the environment and abs = 6.

local old = getfenv();
setfenv(1, setmetatable({}, {__index = function(s,k) return old[k] or {abs = 6} ;end;}));

--Now everyone has abs!
print(swag.abs);
Report Abuse
Nyxis is not online. Nyxis
Joined: 15 Nov 2012
Total Posts: 3374
14 May 2014 02:04 AM
:c

I've never used getfenv, or setfenv. Is it useful?
Report Abuse
smiley599 is not online. smiley599
Joined: 23 Jan 2010
Total Posts: 21869
14 May 2014 02:06 AM
smiley599 = game.Players:WaitForChild("smiley599")
abs=Instance.new("IntValue",smiley599)
abs.Name="abs"
abs.Value=6

print(smiley599.abs.Value)
> 6



lel
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
14 May 2014 02:09 AM
Well it was removed in Lua 5.2 but now the environment is just _ENV
But it's not really useful unless you get into like, sandboxing or APIs/modules (which you can easily return a table, but it's just easier to return the env.)

A basic example being:

workspace.lol (module script)

local hidden = 123;
printHidden = function()
print(hidden);
end;

return getfenv();

lol2 (script)

local API = require(workspace.lol)
API.printHidden(); --123
print(API.hidden); --nil


Or you can have some fun and do:
setfenv(1, require(workspace.lol));
printHidden(); --123
print(hidden); --nil
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
14 May 2014 02:10 AM
Since Roblox uses Lua 5.1 you don't have to worry about not using set/getFenv and _ENV doesn't exist (getfenv() returns that pretty much)
Report Abuse
masterCameron101 is not online. masterCameron101
Joined: 28 Mar 2010
Total Posts: 1377
14 May 2014 04:41 AM
@Nyxis I lol'd at "'abs' is not a valid member ofsmiley599" (pun). :P

~masterCameron101, advanced Lua programmer, certified in Photoshop and geek. Have I help you? If so; support me by buying gear from any of my games, I'd appreciate it!~
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
14 May 2014 08:58 AM
@Cnt
X is -5, 5, and 0
(X ^ 2) ^ 0.5
5, 5, 0
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
14 May 2014 05:55 PM
I wasn't talking about that part.
I meant that abs takes only 1 argument, not infinite and selects the first one.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
14 May 2014 09:58 PM
print(math.abs(-5, 6, 0)) -->5
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
14 May 2014 10:00 PM
That's what should happen. There are no limits for entering arguments, for a lot language in fact.

function do(printStuff)
print(printStuff);
end

do("a", "this is not going to print, it will be ignored since there is no reference");
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
14 May 2014 10:04 PM
'I meant that abs takes only 1 argument, not infinite and selects the first one.'
Then why did you say that?
I'm probably just not understanding sorry .3.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
14 May 2014 10:05 PM
Oh wait I see what you mean, sorry, Im an idiot ;o
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