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

Calling function in a function

Started by pinksheep00, 17 March 2013 - 02:26 PM
pinksheep00 #1
Posted 17 March 2013 - 03:26 PM
Is there to store a function in a variable and call it inside a function?

something like this…

local function foo(x, y, z)
  if x == y then
	z
  end
end
local function anotherFoo()
  print("equal")
end
foo(1, 1, anotherFoo)
Lyqyd #2
Posted 17 March 2013 - 03:41 PM
Split into new topic.

Change to z() inside that if statement.
Bubba #3
Posted 18 March 2013 - 05:26 AM
Another thing you can do is define functions inside of functions.

local function printResult()
  local function getResult()
	return "This is the result..."
  end
  print(getResult())
end

That is probably not exactly what you want, but I thought it might belong in the same category.