Identifying a request from event

The documentation says that networkRequest event.requestId can be used to identify the request. I find this a bit difficult since requestId is a userdata pointer to unkown data and the pointer in the event points to a different address than what network.request returns. As I am doing multiple simultaneous requests I need to know which one has ended.

Any help would be appreciated.

Remembered I can do it with closures so problem solved.

Remembered I can do it with closures so problem solved.

I am with the same problem. I didn’t understand how you solved. Do you mind sharing some code?

You can do it with lua closures. For example (code not checked) define a function for requests where you pass in request id:

function getRequest(url, params, id) local function networkListener(event) if event.isError then print("Error "..tostring(id)) else print("Success! "..tostring(id)) end end network.request(url, "GET", networkListener, params) end

Thanks for the response.

Ah, ok. You are using your own identifier. I am trying to use the requestId returned by the network.request.

So did I but as I wrote in my original post it’s not possible. The id returned from network.request is only good for canceling the request.

Thanks you very much for this simple fix I wouldn’t have thought of myself!

I am with the same problem. I didn’t understand how you solved. Do you mind sharing some code?

You can do it with lua closures. For example (code not checked) define a function for requests where you pass in request id:

function getRequest(url, params, id) local function networkListener(event) if event.isError then print("Error "..tostring(id)) else print("Success! "..tostring(id)) end end network.request(url, "GET", networkListener, params) end

Thanks for the response.

Ah, ok. You are using your own identifier. I am trying to use the requestId returned by the network.request.

So did I but as I wrote in my original post it’s not possible. The id returned from network.request is only good for canceling the request.

Thanks you very much for this simple fix I wouldn’t have thought of myself!