hemen Posted July 11, 2010 Share Posted July 11, 2010 How to read variable from server-side script in client-side script? I tryed to write variable in file, and read by triggerServerEvent, buy it gave me any warnings. --server-side function fileOpenFunc(file,dir) file = fileOpen(dir) end addEvent("a_fileOpen",true) addEvent("a_fileOpen",getRootElement(),fileOpenFunc) function fileReadFunc(file,text) text=fileRead(file,15) end addEvent("a_fileRead",true) addEvent("a_fileRead",getRootElement(),fileReadFunc) function fileCloseFunc(file) fileClose(file) end addEvent("a_fileClose",true) addEvent("a_fileClose",getRootElement(),fileWriteFunc) --client-side local file = nil local text = nil triggerServerEvent("a_fileOpen",file,"/properties/"..row..".txt") triggerServerEvent("a_fileRead",file,text) triggerServerEvent("a_fileClose",file) I tryed return variable by triggerServerEvent, but it also gave me any warnings. Link to comment
MaddDogg Posted July 11, 2010 Share Posted July 11, 2010 To exchange data between the server and client, I advise you'd use getElementData and setElementData. triggerServerEvent or triggerClientEvent don't return a value from "the other end", because there is no direct connection to a function returning a value, the event, to which the function was bound and the triggering from the other side. Also, you added the events twice. I guess you forgot the "-Handler" for example at this point: addEvent("a_fileOpen",getRootElement(),fileOpenFunc) Link to comment
DiSaMe Posted July 11, 2010 Share Posted July 11, 2010 Or you can trigger another client event from server which would contain the 'return' value. But element data is still easier and more efficient way. Link to comment
eAi Posted July 12, 2010 Share Posted July 12, 2010 It's only more efficient if you intend every client to get the element data. Otherwise, events can be more efficient as they're directed at single clients. Returning data to the server with element data sends that data to all the other clients too, which is probably not what you want here. So, I'd use events generally. Use element data for what it's intended for - synchronising the state of elements. 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