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: Can you pass functions as arguments

Previous Thread :: Next Thread 
SenseiWarrior is not online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
04 Oct 2015 05:16 PM
things like

function1(function()--[[code]]end)

remoteevent:FireServer(function()--[[code]]end)


Instance.new("BodyVelocity",SenseiWarrior).velocity = CFrame.new(SenseiWarrior.Torso.Position,YourGirlsDMs.Position).lookVector * 10
Report Abuse
progatician is not online. progatician
Joined: 30 Aug 2013
Total Posts: 8429
04 Oct 2015 05:16 PM
yes
Report Abuse
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
04 Oct 2015 05:20 PM
No
Report Abuse
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
04 Oct 2015 05:21 PM
And it's a bad idea
Report Abuse
Xsitsu is not online. Xsitsu
Joined: 28 Jul 2009
Total Posts: 2921
04 Oct 2015 05:22 PM
You can definitely pass functions as arguments. You already do it all the time when you connect functions to events.
Report Abuse
progatician is not online. progatician
Joined: 30 Aug 2013
Total Posts: 8429
04 Oct 2015 05:26 PM
In Sensei's example, I don't think you actually can.

It treats the function as a userdata value.
Report Abuse
progatician is not online. progatician
Joined: 30 Aug 2013
Total Posts: 8429
04 Oct 2015 05:28 PM
Server:

local lol = Instance.new("RemoteEvent", workspace)
lol.OnServerEvent:connect(function(func)
func()
end)

Client:

local rm = workspace:WaitForChild("RemoteEvent")

rm:FireServer(function() print'hi' end)

Error:

Workspace.Script:3: attempt to call local 'func' (a userdata value)
Report Abuse
progatician is not online. progatician
Joined: 30 Aug 2013
Total Posts: 8429
04 Oct 2015 05:29 PM
Crap.

It does work.

I forgot about the automatic player argument server side.
Report Abuse
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
04 Oct 2015 05:35 PM
Doesn't work in live servers
Report Abuse
SenseiWarrior is not online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
04 Oct 2015 05:41 PM
Is there anyway I could do this through remote events then?


Instance.new("BodyVelocity",SenseiWarrior).velocity = CFrame.new(SenseiWarrior.Torso.Position,YourGirlsDMs.Position).lookVector * 10
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
04 Oct 2015 05:45 PM
You can't send a function created on the client to the server or vice-versa.
Report Abuse
progatician is not online. progatician
Joined: 30 Aug 2013
Total Posts: 8429
04 Oct 2015 05:46 PM
I only tested in Play Solo.
Report Abuse
buildersteven4 is not online. buildersteven4
Joined: 08 May 2009
Total Posts: 1325
04 Oct 2015 05:48 PM
module scripts can be required from both the client and the server. place a function in it and you have that function at both sides. but you might want to choose what function to send. In that case you just place all the function in a table in the module script and then instead of sending the function just send the key of the function you want to call.
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