This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
bobmandude9889's profile picture

Can You Call A Function Using A Variable

Started by bobmandude9889, 18 October 2013 - 11:59 PM
bobmandude9889 #1
Posted 19 October 2013 - 01:59 AM
For example


function function()
print("abc")
end
local var = "function"
var()

If there is no way thats fine. Just wanted to know.

Thanks!
bobmandude9889 #2
Posted 19 October 2013 - 02:11 AM
Never mind! I found out you can do this


local var = test

function test()
print("abc")
end

pcall(var,...)
theoriginalbit #3
Posted 19 October 2013 - 02:15 AM
What you found is really not the same as you first asked. Basically what you're doing there is this

function test()
  print("abc")
end
pcall(test, ...)

If you were to do this

local var = test

local function test()
  print("abc")
end

pcall(var, ...)
It would not work, have a read of the spoiler in this reply to find out why.
Zudo #4
Posted 19 October 2013 - 03:55 AM

local function something()
 print('hi')
end

local doThat = something

doThat()

Is that what you are looking for?
theoriginalbit #5
Posted 19 October 2013 - 04:42 AM

local function something()
print('hi')
end

local doThat = something

doThat()

Is that what you are looking for?
That is the same thing as this, just with locals

Never mind! I found out you can do this


local var = test

function test()
print("abc")
end

pcall(var,...)