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
|
  |
| Joined: 23 Jan 2008 |
| Total Posts: 5350 |
|
|
| 11 Aug 2014 11:23 AM |
| loadstring, which is soon to be depreciated |
|
|
| Report Abuse |
|
|
ColdSmoke
|
  |
| Joined: 02 Jan 2012 |
| Total Posts: 5784 |
|
|
| 11 Aug 2014 11:23 AM |
if string == 'function24' then function24() end |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 06 May 2014 |
| Total Posts: 1166 |
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 15 Nov 2008 |
| Total Posts: 2528 |
|
| |
|
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
|
  |
| Joined: 15 Nov 2008 |
| Total Posts: 2528 |
|
|
| 12 Aug 2014 09:41 AM |
| loadstring'll be removed soon so not really |
|
|
| Report Abuse |
|
|
KAAK82
|
  |
| Joined: 06 May 2014 |
| Total Posts: 1166 |
|
| |
|
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
|
  |
| 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 |
|
|