|
| 08 Jun 2016 06:57 PM |
How come you can't transfer a function to a server through a remote event?
For example:
In Local Script: RemoteEvent:FireServer( Table = { TestFunction = function() end } )
In Server: RemoteEvent.OnServetEvent:connect(function(Table) print(Table.TestFunction) end)
How come "TestFunction" is non existent on the server? |
|
|
| Report Abuse |
|
|
| |
|
| |
|
Rerumu
|
  |
| Joined: 11 Oct 2014 |
| Total Posts: 950 |
|
|
| 08 Jun 2016 07:47 PM |
| You can't pass functions as arguments in between server and client in any way. I've tested it but your best bet is to send the server a string to loadstring()() |
|
|
| Report Abuse |
|
|
| |
|
Rerumu
|
  |
| Joined: 11 Oct 2014 |
| Total Posts: 950 |
|
|
| 08 Jun 2016 09:13 PM |
| I tried JSON encoding them, didn't even work. |
|
|
| Report Abuse |
|
|
Rerumu
|
  |
| Joined: 11 Oct 2014 |
| Total Posts: 950 |
|
|
| 08 Jun 2016 09:17 PM |
local func = [[ function Stuff(that) local this = 2 return that*this end ]]
-- Send the func string over through remote function/event. -- On server script you would then do:
local func = ExampleFunction:InvokeClient(player) -- Ex. Of getting the string.
loadstring(func)(Insert_Arguments_Here) -- Call the code. |
|
|
| Report Abuse |
|
|
|
| 08 Jun 2016 09:35 PM |
Probably because the first argument of OnServerEvent is player
|
|
|
| Report Abuse |
|
|
Rerumu
|
  |
| Joined: 11 Oct 2014 |
| Total Posts: 950 |
|
|
| 08 Jun 2016 10:37 PM |
| There is an actual issue with function passing though, same with dictionaries. Overlooking the syntax errors there is a ROBLOX limitation for it. |
|
|
| Report Abuse |
|
|
|
| 08 Jun 2016 10:41 PM |
Why would Roblox go to the vast effort of allowing you to pass functions through them, when it wouldn't even be practical for anything but messing around?
|
|
|
| Report Abuse |
|
|
Rerumu
|
  |
| Joined: 11 Oct 2014 |
| Total Posts: 950 |
|
|
| 08 Jun 2016 10:47 PM |
Because messing aroUND IS LIFEEE. That's how I made my Text Filter script, by messing around. And by messing around it outclassed ROBLOX's own filter. |
|
|
| Report Abuse |
|
|
|
| 08 Jun 2016 11:38 PM |
| Do you know how insanely complicated it would be to implement passing functions across the server-client boundary? You don't think of it now but you have to clone the function's environment, the upvalues, and the prototype itself. The environment and upvalues may, and probably will, contain other functions, tables, userdata that exists only on the client (of which may also contain functions and so on). It's incredibly impractical, and even if it were possible if you find a need to actually send a function then you are most likely doing something wrong. |
|
|
| Report Abuse |
|
|
Rerumu
|
  |
| Joined: 11 Oct 2014 |
| Total Posts: 950 |
|
|
| 08 Jun 2016 11:44 PM |
I'm not talking about the function with the entire environment this and that, I'm saying the body of the function itself. Passing a function as in:
function Add(a,b) return a+b end
Now if a variable were to be defined somewhere else outside the function:
function Add(a) return a+b -- b is defined outside of function body. end
Then ROBLOX could simply nil it. It's as easy as making the function to string and loadstring'ng it on the server before usage. |
|
|
| Report Abuse |
|
|
|
| 09 Jun 2016 12:01 AM |
| No, because a lot of people would complain lol |
|
|
| Report Abuse |
|
|
Hedr0n
|
  |
| Joined: 05 Jan 2016 |
| Total Posts: 1524 |
|
|
| 09 Jun 2016 12:48 AM |
| @cn where do I go to get a Lua vm installed into my brain like you |
|
|
| Report Abuse |
|
|