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
|
  |
| 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
|
  |
| Joined: 10 May 2015 |
| Total Posts: 14729 |
|
|
| 26 Mar 2017 05:31 PM |
how do you think the connect method works...
|
|
|
| Report Abuse |
|
|
|
| 26 Mar 2017 05:35 PM |
Functions are completely first-class values in Lua.
|
|
|
| Report Abuse |
|
|
|
| 26 Mar 2017 05:35 PM |
You can, but not through remote events/functions
|
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 27 Mar 2017 03:22 AM |
Clearly you don't know what you're talking about. [2]
capitalist atheist |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 30 Mar 2017 09:49 PM |
htt()p:/()/wiki.roblox(.)com/index(.)php?title=RBX()ScriptSignal
Delete the ()'s |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 31 Mar 2017 03:29 AM |
"Methods are not equal to functions"
local t = {}
function t:hello()
end
"function"
capitalist atheist |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 31 Mar 2017 05:25 AM |
| Lmao ROBLOX Lua is normal Lua just one thousand limitations and a fancy sandbox. |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2017 06:07 AM |
You could if RBX.Lua had pointers and references... sadly they don't 3:
|
|
|
| Report Abuse |
|
|
| |
|
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 |
|
|