Jump to content

Table server->client doesnt work as should?


zixxonx

Recommended Posts

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

Link to comment

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) 

Link to comment

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