xXMADEXx Posted March 28, 2015 Share Posted March 28, 2015 Hey guys. I'm having trouble with triggerClientEvent. For some reason, it's not sending my "mods" table from the server to the client. On the server, "mods" is a table (I have confirmed it - see screenshot), but when I trigger it to the client, it becomes nil somewhere along the way, and I'm absolutely clueless why. I think it might be some basic bug I've written on accident that I can't find. Ignore the timers, I was trying to see if it had something to do with that, but it doesn't. Debug log: http://i.imgur.com/sB6yKCa.png Client Script (cMods.lua and cDownloader.lua) -------------------------------------- -- cMods.lua -- -------------------------------------- Mods = { } -- Mods Constructor function Mods:Mods ( ) for i = 1, 20 do outputChatBox ( " " ); end setTimer ( function ( ) -- Did the server have time to load the list?? outputDebugString ( "From Mods:Mods -> Downloader:Request( )" ); Downloader:RequestList ( ); -- Get list from server end, 5000, 1 ); end -- Mods:PhraseList -> Used to check mods list for enabled mods function Mods:PhraseList ( ) local list = Downloader:GetList ( ) -- Get list from Downloader class outputChatBox ( "Phrasing" ); -- Loop through the list and find completed downloaded files for index, mod in pairs ( list ) do list [ index ].enabled = false; local name = mod.name; local txd = mod.txd; local dff = mod.dff; local replace = mod.replace; outputChatBox ( tostring ( name ) ); end end addEventHandler ( "onClientResourceStart", resourceRoot, Mods.Mods ); -------------------------------------- -- cDownloader.lua -- -------------------------------------- Downloader = { } Downloader.Mods = { } -- Downloader Constructor function Downloader:Downloader ( ) end -- Downloader:RequestList -> Used to request vehicle mod list from server function Downloader:RequestList ( ) outputDebugString ( "Downloader:RequestList -> Sending server request" ); triggerServerEvent ( "ModDownloader:RequestFilesFromServer", localPlayer, localPlayer ); end -- Downloader:GetList -> Used to get the mods list downloaded from server function Downloader:GetList ( ) outputDebugString ( "Downloader:GetList called" ); return Downloader.Mods; end -- Downloader:HandleRequest -> Used to handle response from the server for the mod list function Downloader:HandleResponse ( list ) outputDebugString ( "From Server -> Downloader:HandleResponse called. List: ".. tostring ( list ) ); Downloader.Mods = list; setTimer ( function ( ) outputChatBox ( "Got" ); Mods:PhraseList ( ); end, 500, 1 ); end addEvent ( "ModDownloader:OnServerSendClientModList", true ); addEventHandler ( "ModDownloader:OnServerSendClientModList", root, Downloader.HandleResponse ); Server Script (sLoader.lua) Not the whole script - the rest is loading/creating of the XML file -- Loader:HandleRequest -> Handles request of mod files from client -- Sends client new mod list function Loader:HandleRequest ( plr ) outputDebugString ( "From client: Got request list -> sending response. List: ".. tostring ( mods ).. " | source: "..tostring ( source ) ); triggerClientEvent ( source, "ModDownloader:OnServerSendClientModList", source, mods ); end addEvent ( "ModDownloader:RequestFilesFromServer", true ); addEventHandler ( "ModDownloader:RequestFilesFromServer", root, Loader.HandleRequest ); Link to comment
WhoAmI Posted March 28, 2015 Share Posted March 28, 2015 Check what the type of mods is by using type Also you are triggering to server double localPlayer - as source and argument. What is it for? Also try to trigger another thing, not only list of mods and check if it returns correct value in client side. Link to comment
xXMADEXx Posted March 28, 2015 Author Share Posted March 28, 2015 Check what the type of mods is by using type Also you are triggering to server double localPlayer - as source and argument. What is it for? Also try to trigger another thing, not only list of mods and check if it returns correct value in client side. mods is definitely a table on the server side (I've confirmed it) I used double localPlayer, because at first the server-script was setup for that input, but I changed it thinking that could be the reason. I've just tried: function Loader:HandleRequest ( plr ) local mods = "test"; outputDebugString ( "From client: Got request list -> sending response. List: ".. tostring ( mods ).. " | source: "..tostring ( source ) ); triggerClientEvent ( source, "ModDownloader:OnServerSendClientModList", source, mods ); end addEvent ( "ModDownloader:RequestFilesFromServer", true ); addEventHandler ( "ModDownloader:RequestFilesFromServer", root, Loader.HandleRequest ); and list is still returning as nil on the client side. Link to comment
WhoAmI Posted March 28, 2015 Share Posted March 28, 2015 That's really weird. I can't see any error or mistake in your code. It has to work... Well, maybe it will cause nothing, but try to call another event in HandleRequest function to another file with client event. Also check if files are in coded in UTF-8. Sometimes it can be a problem. And check type ( source ) in client side if it returns userdata. Link to comment
xXMADEXx Posted March 28, 2015 Author Share Posted March 28, 2015 That's really weird. I can't see any error or mistake in your code. It has to work... Well, maybe it will cause nothing, but try to call another event in HandleRequest function to another file with client event. Also check if files are in coded in UTF-8. Sometimes it can be a problem.And check type ( source ) in client side if it returns userdata. Yeah, it's extremely weird. Files are indeed encoded in UTF-8. I even tried this: -- Downloader:HandleRequest -> Used to handle response from the server for the mod list function Downloader:HandleResponse ( list ) outputDebugString ( "From Server -> Downloader:HandleResponse called. List: ".. tostring ( list ) ); Downloader.Mods = list; setTimer ( function ( ) Mods:PhraseList ( ); end, 500, 1 ); if ( source and source == localPlayer ) then triggerEvent ( "ModDownloader:OnServerSendClientModList", resourceRoot, "LOL TEST - 2" ); end end addEvent ( "ModDownloader:OnServerSendClientModList", true ); addEventHandler ( "ModDownloader:OnServerSendClientModList", root, Downloader.HandleResponse ); and list is still returning nil. Link to comment
xXMADEXx Posted March 28, 2015 Author Share Posted March 28, 2015 Found the problem. Had to change the function name from "Downloader:HandleResponse" to "Downloader.HandleResponse", and it works fine. Lol, probably something to do with OOP. Link to comment
WhoAmI Posted March 28, 2015 Share Posted March 28, 2015 Yea, wanted to ask about OOP, that it would be the problem and it really is. Link to comment
Gallardo9944 Posted March 28, 2015 Share Posted March 28, 2015 I suggest you not to use trigger(Latent)ClientEvent for sending files. It's very CPU intensive. Better fetchRemote clientside Link to comment
xXMADEXx Posted March 28, 2015 Author Share Posted March 28, 2015 I suggest you not to use trigger(Latent)ClientEvent for sending files. It's very CPU intensive. Better fetchRemote clientside Its not actually sending files, it just sending file paths and their hashes. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now