JeViCo Posted December 30, 2018 Share Posted December 30, 2018 Hi there! I've recently discovered 2 problems: 1. I can't trigger fetchRemote inside another fetchRemote function. Example: fetchRemote("http_stuff",function(resp) -- everything OK here -- some magic here myfunc("some_args") end) function myfunc(args) fetchRemote("httpStuff_x2",function(resp2) print("done x2") end) -- it won't trigger but i'll see 'done x2' message end 2. i can't store information into variables inside fetchRemote func. Example: local variable fetchRemote("http_stuff",function(resp) -- everything OK here variable = resp print(variable) -- OK end) print(variable) -- nil I don't know what to do Link to comment
Moderators IIYAMA Posted December 30, 2018 Moderators Share Posted December 30, 2018 (edited) @JeViCo The syntax: bool fetchRemote ( string URL[, string queueName = "default" ][, int connectionAttempts = 10, int connectTimeout = 10000 ], function callbackFunction, [ string postData = "", bool postIsBinary = false, [ arguments... ] ] ) Problem 1 Always be called The callback function will always be called, even if there is an error. function myCallback( responseData, errno ) if errno == 0 then Problem 2 Execution order: Line: 1 local variable Line: 2 fetchRemote("http_stuff", Making a network request. Line: 6 Line: 7 print(variable) -- nil ------------------------------------------------------------------------------------------------- ---------- Waiting for the network request to be finished ---------- ------------------------------------------------------------------------------------------------- Line: 2 function(resp) Callback function will be called after a delay. The delay can be long or short, depending on the response. If not response, it will be called eventually with an error. connectTimeout: Number of milliseconds each connection attempt will take before timing out https://wiki.multitheftauto.com/wiki/FetchRemote Line: 3 variable = resp Line: 4 print(variable) -- OK Line: 5 end) Callback functions in combination with the network are always async. The code doesn't wait for these callback functions. Edited December 30, 2018 by IIYAMA 1 Link to comment
JeViCo Posted December 31, 2018 Author Share Posted December 31, 2018 thank you so much @IIYAMA i fixed my problem) 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