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
 

Calling a Function using Strings

Previous Thread :: Next Thread 
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
11 Aug 2014 11:22 AM
I would like to Know, how exactly would I Call a Function using a String?
Report Abuse
Bobobob12 is not online. Bobobob12
Joined: 23 Jan 2008
Total Posts: 5350
11 Aug 2014 11:23 AM
loadstring, which is soon to be depreciated
Report Abuse
ColdSmoke is not online. ColdSmoke
Joined: 02 Jan 2012
Total Posts: 5784
11 Aug 2014 11:23 AM
if string == 'function24' then
function24()
end
Report Abuse
12packkid is not online. 12packkid
Joined: 24 Jun 2011
Total Posts: 1418
11 Aug 2014 11:24 AM
Client load string will be removed on August 16th.
You have 5 days, make the best of it.

You can also call functions the depreciated way, e.g:

workspace:breakJoints'';
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
11 Aug 2014 11:28 AM
12p, u mean, like (if Text == 'Function' then 'Text';)? and about loadstring, are yas sayin I needa say (if lalal then a = loadstring(Text) a(and arguments here))?
Report Abuse
12packkid is not online. 12packkid
Joined: 24 Jun 2011
Total Posts: 1418
11 Aug 2014 11:40 AM
text = 'blah'

if text:lower() == 'blah' then
blah,err = function() --[[do code]] end
if blah then
coroutine.resume(coroutine.create(function()
loadstring([[print'hi' blah() ]])
end))
else
return error(err)
end
end
Report Abuse
sbk28 is not online. sbk28
Joined: 15 Nov 2008
Total Posts: 2528
11 Aug 2014 11:41 AM
local TableOfFunctions = {

["Function1"] = function(...) --[[ code ]] end;
["Function2"] = function(...) --[[ code ]] end;
["Function3"] = function(...) --[[ code ]] end;

}

local string = "Function1"

TableOfFunctions[string](...)
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
11 Aug 2014 11:46 AM
thnx
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
12 Aug 2014 08:39 AM
wat about if there are Arguments in the String?

Commands[String:match(%a(Symbol)-)](%(Symbol)+)
Report Abuse
sbk28 is not online. sbk28
Joined: 15 Nov 2008
Total Posts: 2528
12 Aug 2014 09:12 AM
local TableOfFunctions = {

["Function1"] = function(...) --[[ code ]] end;
["Function2"] = function(...) --[[ code ]] end;
["Function3"] = function(...) --[[ code ]] end;

}

local string = "Function1(abc,cde,efg)"

local func, args = string:match("(%w+)(%b())")
local args = string.sub(args, 2, #args - 1)
local argtable = {}
for arg in string.gmatch(args, "%w+") do
table.insert(argtable, arg)
end

TableOfFunctions[func](argtable)
Report Abuse
sbk28 is not online. sbk28
Joined: 15 Nov 2008
Total Posts: 2528
12 Aug 2014 09:13 AM
local TableOfFunctions = {

["Function1"] = function(...) --[[ code ]] end;
["Function2"] = function(...) --[[ code ]] end;
["Function3"] = function(...) --[[ code ]] end;

}

local string = "Function1(abc,cde,efg)"

local func, args = string:match("(%w+)(%b())")
local args = string.sub(args, 2, #args - 1)
local argtable = {}
for arg in string.gmatch(args, "[%P%S]+") do
table.insert(argtable, arg)
end

TableOfFunctions[func](argtable)

**
Report Abuse
sbk28 is not online. sbk28
Joined: 15 Nov 2008
Total Posts: 2528
12 Aug 2014 09:14 AM
my bad use the first one
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
12 Aug 2014 09:31 AM
thnx sbk, but is there no Shorter way?
Report Abuse
sbk28 is not online. sbk28
Joined: 15 Nov 2008
Total Posts: 2528
12 Aug 2014 09:41 AM
loadstring'll be removed soon so not really
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
12 Aug 2014 09:47 AM
crap... :'(
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
12 Aug 2014 09:49 AM
loadstring will still work so long as you don't use it in a LocalScript.
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
12 Aug 2014 10:16 AM
k, thnx... but how should I use loadstring to do the Job? cos the Arguments are still Strings...

TextBox.Text = 'TestFunction(Object)' --Text = String --- Object = Instance
so how should I do this with loadstring???
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