Jump to content

Copy a table from the client to servers seems impossible


botanist

Recommended Posts

Posted

Hi thar, after some inactivity I picked my Handling Editor project back up and started with optimalization of the code. But, now I need to get a table that's made clientside into the server using triggerServerEvent. What I'm currently doing does not work:

-- Client 
log = {} -- Not local! 
log.succes = "Test String" 
triggerServerEvent ( "onEvent", blah, log ) -- Where "blah" are some irrelevant arguments 
  
-- Server 
addEvent ( "onEvent", true ) 
addEventHandler ( "onEvent", root, 
    function ( blah, log ) 
        string.format ( log.succes, blah ) -- Produces the "Not Indexed" error 
    end 
) 

Is there any way to do this correct?

Posted

Look at the 2nd parameter of the triggerServerEvent function: it is a variable representing the source of the function you call. So:

-- Client 
log = {} -- Not local! 
log.succes = "Test String" 
triggerServerEvent ( "onEvent", getLocalPlayer(), blah, log ) 
  
-- Server 
addEvent ( "onEvent", true ) 
addEventHandler ( "onEvent", root, 
    function ( blah, log ) 
        string.format ( log.succes, blah ) 
    end 
) 

  • Discord Moderators
Posted

triggerServerEvent second parameter is element source. This argument isn't passed as function argument but in source form. Therefore your blah argument is log, and log argument is nil (if that makes sense :P).

edit: fuck snap I'm being overhauled D:

Posted
triggerServerEvent ( "onEvent", getLocalPlayer(), blah, log ) 

Which is included with the "blah" arguments, forgot to mention that :P So, that can't be the reason.

Wait, I think I got the problem. Give me a moment.

Yep, stupid me. I always forget to check variablenames for any mistakes. So, solved. Lol.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...