Jump to content

Table server->client doesnt work as should?


zixxonx

Recommended Posts

Posted

Hello! I have problem when using server-sided table on client-side

Let's take this table as a example:

informations = { 
   serverPort = 661, 
   players = { } 
} 

It's server sided. Now i want to pass this table to client-side. I've found something like this:

setTimer(triggerClientEvent, 1000, 0, "updateClientTable", root, informations)

It works flawlessy, but. When on client-side i do something like

informations = {} 
addEvent ( "updateClientTable", true ) 
addEventHandler ( "updateClientTable", root, 
    function ( _table) 
        informations = _table 
    outputChatBox(informations.serverPort) 
    end 
) 

It shows 661. When i use:

outputChatBox(#informations.players) to show how much players i've added it shows 0 even if it shows good amount on server side.

Example server code:

informations = { 
   serverPort = 661, 
   players = { } 
} 
local function addToTable() 
    for i,v in ipairs(getElementsByType('player')) do 
        informations.players[i] = v 
    end 
    outputChatBox('players: '.. #informations.players) 
end 
addEvent('onMapStarting', true) 
addEventHandler ( "onMapStarting", root, addToTable)  

3fZ2PnW.jpg

Posted

It's very strange 'cause I checked your code and it works fine for me. Maybe you're counting players not at the moment you need and it returns 0. Check it more closely.

Posted

OMG. Forgive me. Foolish mistake. It've should been

function startRefreshing() 
    setTimer(triggerClientEvent, 1000, 0, "updateClientTable", root, informations) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), startRefreshing) 

instead of

    setTimer(triggerClientEvent, 1000, 0, "updateClientTable", root, informations) 

Posted (edited)

Oh mate, I don't know how you are triggering your custom event 'onMapStarting', but I tried to change it, for example, to 'onResourceStart' and it works perfectly. Maybe that's your place where you went wrong.

Edited by Guest

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...