doepey590
|
  |
| Joined: 16 Sep 2008 |
| Total Posts: 1187 |
|
|
| 16 Mar 2013 02:19 PM |
I have a function, I want to use one of the arguments of the function as code for another function set within the function.
Is there any way to do this? if so how?
(preferably without using Roblox specific functions.) |
|
|
| Report Abuse |
|
|
dekkonot
|
  |
| Joined: 22 Dec 2010 |
| Total Posts: 6685 |
|
|
| 16 Mar 2013 02:20 PM |
function applyfunc(funct, argu) funct(argu) end
funct(arrg) print(arrg) end |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 16 Mar 2013 02:24 PM |
----------------------------------------------- function runFunctionPack(...) -- note 1* for _,f in pairs({...}) do f(1) -- note 2* end end
runFunctionPack(function(number) print("Test 1", number) end)
local function a(test) print(test + 2) end local function b(test) print(test * 20) end
runFunctionPack(a, b)
--[[ * Note 1: ... is a tuple of all arguments, meaning that you can pass endless arguments! Note 2: Will run the function with an argument, number 1. ]]
-----------------------------------------------
Uh, should that do the trick? I hope so.
- As, just typed that function stuff here. Nowhere else. KABUM! |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2013 02:29 PM |
| I believe dekk had a simpler example... |
|
|
| Report Abuse |
|
|
doepey590
|
  |
| Joined: 16 Sep 2008 |
| Total Posts: 1187 |
|
|
| 16 Mar 2013 02:31 PM |
The problem is is that the function needs to be assigned in a Table as a variable or method, so like;
function SetTable()
Table.DoThing = function() --stuff end
end
except I need to be able to put the function() --stuff end in an argument.
|
|
|
| Report Abuse |
|
|
|
| 16 Mar 2013 02:33 PM |
function SetTable(argument)
Table.DoThing = argument
end |
|
|
| Report Abuse |
|
|
doepey590
|
  |
| Joined: 16 Sep 2008 |
| Total Posts: 1187 |
|
|
| 16 Mar 2013 02:36 PM |
| The problem is is that it sets it to what the argument function returns, not the argument function is. |
|
|
| Report Abuse |
|
|
DrHaximus
|
  |
| Joined: 22 Nov 2011 |
| Total Posts: 8410 |
|
|
| 16 Mar 2013 03:00 PM |
void func(void(*otherFunc)()) { (*otherFunc)(); }
:p
- DrHaximoose |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2013 03:02 PM |
@OP
No... it doesn't.
The function is not called. |
|
|
| Report Abuse |
|
|
dekkonot
|
  |
| Joined: 22 Dec 2010 |
| Total Posts: 6685 |
|
|
| 16 Mar 2013 03:04 PM |
| If you add perenthesis, yes. |
|
|
| Report Abuse |
|
|
doepey590
|
  |
| Joined: 16 Sep 2008 |
| Total Posts: 1187 |
|
|
| 16 Mar 2013 03:15 PM |
@Prehistoricman Ye, sorry, Didn't realise the whole time I was calling the Argument by the wrong name |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2013 04:19 PM |
@DrHaximus
YOU CAN DO THAT? :O |
|
|
| Report Abuse |
|
|
DrHaximus
|
  |
| Joined: 22 Nov 2011 |
| Total Posts: 8410 |
|
|
| 16 Mar 2013 04:20 PM |
@Awsum
Yes sir. Have fun.
- DrHaximoose |
|
|
| Report Abuse |
|
|