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 parameters?

Previous Thread :: Next Thread 
Raildex is not online. Raildex
Joined: 06 Dec 2009
Total Posts: 934
26 Mar 2017 05:29 PM
I believe I saw this somewhere but im not sure. Can someone clear this up for me? If i can, how?
Report Abuse
hasang1 is not online. hasang1
Joined: 09 Nov 2012
Total Posts: 903
26 Mar 2017 05:31 PM
Yesz.
Messy example:
local func1=function(func2)
func2()
end
func1(function() print("Hi.") end)


HAX.
Report Abuse
Isosta is not online. Isosta
Joined: 10 May 2015
Total Posts: 14729
26 Mar 2017 05:31 PM
how do you think the connect method works...


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
26 Mar 2017 05:35 PM
Functions are completely first-class values in Lua.


Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
26 Mar 2017 05:35 PM
You can, but not through remote events/functions


Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Mar 2017 07:08 PM
Or bindables
Or signals (from createsignal in rbxutility)
or in a lot of places where they should work
because roblox is cancer
Report Abuse
Kyles45678 is online. Kyles45678
Joined: 12 Dec 2012
Total Posts: 203
26 Mar 2017 08:03 PM
You can send a function through parameters, as long as the function you are sending returns a value that fits the parameter.

local GetRan = function(a, b)
return math.random(a, b)
end

local TryDis = function(ranNum)
print(ranNum)
end

TryDis(GetRan(1, 10))
Report Abuse
Kyles45678 is online. Kyles45678
Joined: 12 Dec 2012
Total Posts: 203
26 Mar 2017 08:05 PM
The connect method does not use functions as parameters unless you make it. All the connect method does is connect a function to happen to an event. It is not the same as sending a function as a parameter to another function.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
26 Mar 2017 08:08 PM
"You can send a function through parameters, as long as the function you are sending returns a value that fits the parameter."

No. As I said earlier, Lua functions are first-class values.


Report Abuse
Isosta is not online. Isosta
Joined: 10 May 2015
Total Posts: 14729
27 Mar 2017 01:09 AM
Treat the function like any other value and then some.


Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
27 Mar 2017 01:12 AM
"The connect method does not use functions as parameters unless you make it. All the connect method does is connect a function to happen to an event. It is not the same as sending a function as a parameter to another function."
Clearly you don't know what you're talking about.
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
27 Mar 2017 03:22 AM
Clearly you don't know what you're talking about. [2]


capitalist atheist
Report Abuse
Isosta is not online. Isosta
Joined: 10 May 2015
Total Posts: 14729
27 Mar 2017 03:28 AM
Kyle, were you born without a brain, or how did that come to develop?


Report Abuse
Kyles45678 is online. Kyles45678
Joined: 12 Dec 2012
Total Posts: 203
30 Mar 2017 09:48 PM
###################################################### "A RBXScriptSignal, more commonly known as an Event, is a special kind of ROBLOX object. It provides a way for user-defined functions, called listeners, to be called when something happens in the game. When a certain event happens, the Event is fired, calling any listeners that are connected to the Event. An Event may also pass arguments to each listener, to provide extra information about the event that occurred." Method :Connect(): "Establishes a function to be called whenever the event occurs." Don't insult me, I know what I'm doing. I am speaking in terms of ROBLOX Lua, not Lua in general.
Report Abuse
Kyles45678 is online. Kyles45678
Joined: 12 Dec 2012
Total Posts: 203
30 Mar 2017 09:49 PM
htt()p:/()/wiki.roblox(.)com/index(.)php?title=RBX()ScriptSignal

Delete the ()'s
Report Abuse
Kyles45678 is online. Kyles45678
Joined: 12 Dec 2012
Total Posts: 203
30 Mar 2017 09:53 PM
Like I said, using :connect connects a function to run when an event is trigger. That does not equal the concept of sending functions into functions as parameters. Methods are not equal to functions. A function is a piece of code that is called by name. It can be passed data to operate on (i.e. the parameters) and can optionally return data (the return value). All data that is passed to a function is explicitly passed. A method is a piece of code that is called by a name that is associated with an object. In most respects it is identical to a function except for ### ### differences: A method is implicitly passed the object on which it was called. A method is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data). If you don't know what a class is, you have not been into ACTUAL programming. Lua is only like a skin surface, easy programming.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
30 Mar 2017 11:23 PM
You realize you can make your own connect function? You have to pass a function through it. Just like the regular connect.


Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
30 Mar 2017 11:37 PM
you can send anything to a function
if the function has arguments for the values then they will be set
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
30 Mar 2017 11:38 PM
also you are obviously mistaken about how connect works
it sends the function you give to connect to the event that you called it with (which is why it is a method call) and returns a connection that you can disconnect, so you send a function to connect event.connect( event, func )
otherwise known as event:connect( func )
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
31 Mar 2017 03:29 AM
"Methods are not equal to functions"

local t = {}

function t:hello()

end


"function"


capitalist atheist
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
31 Mar 2017 04:17 AM
"Like I said, using :connect connects a function to run when an event is trigger. That does not equal the concept of sending functions into functions as parameters."
It does, since ":connect()" is a function.


"Methods are not equal to functions."
Until it is compiled, they are essentially the same.
workspace.BasePlate:Destroy() -- Method syntax
workspace.BasePlate.Destroy(workspace.BasePlate) -- Function syntax



"A function is a piece of code that is called by name. It can be passed data to operate on (i.e. the parameters) and can optionally return data (the return value). All data that is passed to a function is explicitly passed. A method is a piece of code that is called by a name that is associated with an object. In most respects it is identical to a function except for ### ### differences: A method is implicitly passed the object on which it was called. A method is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data). If you don't know what a class is, you have not been into ACTUAL programming"

You've been doing too much "ACTUAL" programming. Lua is different.
Report Abuse
shotaaesthetic is not online. shotaaesthetic
Joined: 11 Oct 2014
Total Posts: 881
31 Mar 2017 05:25 AM
Lmao ROBLOX Lua is normal Lua just one thousand limitations and a fancy sandbox.
Report Abuse
GNUnotUNIX is not online. GNUnotUNIX
Joined: 05 Feb 2012
Total Posts: 15171
31 Mar 2017 06:07 AM
You could if RBX.Lua had pointers and references... sadly they don't 3:


Report Abuse
NexanianStudios is online. NexanianStudios
Joined: 16 Jul 2016
Total Posts: 1109
31 Mar 2017 07:40 AM
Function-ception
Report Abuse
Createa is not online. Createa
Joined: 13 Oct 2009
Total Posts: 193
31 Mar 2017 07:50 AM
Why is there so much ignorance surrounding this very simple topic? When you create a function, you create a "proto"type for it. Then, when you "access" it creates an "en"closure around the proto that can also have some other contextual stuff. Closure is a datatype just like number and can have any generic actions performed on it as well as calling. That is pretty much all.

function test() -- proto blueprint created here
print("foobar")
end

local testClosure = test -- closure created here, testClosure is now data just like 5 or "a string"
testClosure() -- specific thing you can do in Lua on things of type closure
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