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 » Scripters
Home Search
 

Re: Functions as arguments

Previous Thread :: Next Thread 
doepey590 is not online. 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 is not online. 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 is online. 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
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
16 Mar 2013 02:29 PM
I believe dekk had a simpler example...
Report Abuse
doepey590 is not online. 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
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
16 Mar 2013 02:33 PM
function SetTable(argument)

Table.DoThing = argument

end
Report Abuse
doepey590 is not online. 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 is not online. DrHaximus
Joined: 22 Nov 2011
Total Posts: 8410
16 Mar 2013 03:00 PM
void func(void(*otherFunc)()) {
(*otherFunc)();
}

:p

- DrHaximoose
Report Abuse
Prehistoricman is not online. Prehistoricman
Joined: 20 Sep 2008
Total Posts: 12490
16 Mar 2013 03:02 PM
@OP

No... it doesn't.

The function is not called.
Report Abuse
dekkonot is not online. dekkonot
Joined: 22 Dec 2010
Total Posts: 6685
16 Mar 2013 03:04 PM
If you add perenthesis, yes.
Report Abuse
doepey590 is not online. 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
awsumpwner27 is not online. awsumpwner27
Joined: 03 Sep 2011
Total Posts: 4389
16 Mar 2013 04:19 PM
@DrHaximus

YOU CAN DO THAT? :O
Report Abuse
DrHaximus is not online. DrHaximus
Joined: 22 Nov 2011
Total Posts: 8410
16 Mar 2013 04:20 PM
@Awsum

Yes sir.
Have fun.

- DrHaximoose
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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