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
|
  |
| 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 |
|
|
|
| 13 May 2014 08:57 PM |
wtf
No more pickles, its all ogre now. |
|
|
| Report Abuse |
|
|
|
| 13 May 2014 08:58 PM |
| veihcleSim, please do not post spam. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 14 May 2014 12:59 AM |
| tonumber only accepts 1 argument |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 14 May 2014 09:58 PM |
| print(math.abs(-5, 6, 0)) -->5 |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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 |
|
|