Kazafka Posted January 28, 2020 Share Posted January 28, 2020 So basically, I wanted to make a function in server-side, that returns some stuff, that has been set-up in GUI, but this server-side function depends on, when some button is clicked, etc. Is there any way to do it? Link to comment
Moderators Patrick Posted January 28, 2020 Moderators Share Posted January 28, 2020 on gui click -> trigger server event -> trigger client event back -> do what you want Link to comment
Kazafka Posted January 28, 2020 Author Share Posted January 28, 2020 (edited) 8 minutes ago, stPatrick said: on gui click -> trigger server event -> trigger client event back -> do what you want Okay, I have now another idea, right? So, how can I make a function, that returns values, that will be set by clicking button? ALL IN CLIENT!!! @stPatrick what do you think 'bout this? /\ /\ /\ Edited January 28, 2020 by VaporZ Link to comment
Moderators Patrick Posted January 28, 2020 Moderators Share Posted January 28, 2020 (edited) 7 minutes ago, VaporZ said: I tried it, but I still wanted to operate these values from client, in functions that return something on server -- CLIENT addEventHandler("onClientGUIClick", BUTTON_ELEMENT, function() local some_button_data = 5 triggerServerEvent("doServerFunction", localPlayer, some_button_data) end) addEvent("doServerFunction:receiveResults", true) addEventHandler("doServerFunction:receiveResults", localPlayer, function(results_from_server_data) outputChatBox(results_from_server_data) -- print: 10 end) addEvent("doServerFunction", true) addEventHandler("doServerFunction", root, function(data_from_client) local need_to_return_this = data_from_client * 2 -- do some magic here triggerClientEvent(source, "doServerFunction:receiveResults", source, need_to_return_this) end) Need to do like this. Edited January 28, 2020 by stPatrick Link to comment
Kazafka Posted January 28, 2020 Author Share Posted January 28, 2020 1 minute ago, stPatrick said: Need to do like this. KK, but how can I return data in different function, set by clicking a button? <<< ALL IN CLIENT!!! 1 minute ago, stPatrick said: 'k, but how can I return data by clicking a button? Sorry for multiple questions in one comment, but my final is: How can I return data by clicking a button? CLIENT Link to comment
Moderators IIYAMA Posted January 28, 2020 Moderators Share Posted January 28, 2020 7 minutes ago, VaporZ said: How can I return data by clicking a button? CLIENT From where are you returning that data? Link to comment
Kazafka Posted January 28, 2020 Author Share Posted January 28, 2020 (edited) 5 minutes ago, IIYAMA said: From where are you returning that data? Example: You have made a scrollbar and you want to return scrollbar position to some variables by clicking button, I mean, some other scripts' variables. Like exports.... That's what I wanna get to my knowledge Edited January 28, 2020 by VaporZ Link to comment
Moderators IIYAMA Posted January 28, 2020 Moderators Share Posted January 28, 2020 2 scripts, within the same resource You can either use globals: some_button_data = 5 addEventHandler("onClientGUIClick", BUTTON_ELEMENT, function() iprint(some_button_data) end) Or return values: local some_button_data = 5 function getData () return some_button_data end addEventHandler("onClientGUIClick", BUTTON_ELEMENT, function() local some_button_data = getData() end) And if you are dealing with multiple resources, you can use exports: Resource 1 <!-- meta.xml --> <export function="getData" type="client"/> local some_button_data = 5 function getData () return some_button_data end Resource 2 addEventHandler("onClientGUIClick", BUTTON_ELEMENT, function() local some_button_data = exports["resourceName"]:getData () end) 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