I read a file with http.request and the file, which is a row of numbers, is in the variable called data.
Now I want to loop throug the rows and save every single row in a new array variable, so I can have acces to each independantly.
I need to know the number of rows in the data and to pick every row and then loop, but how is that practical possible ?
Re Peter
Ps. I know of course how to make a loop. It is the data variable that I cannot understand.
Yes, when the response arrives the callback will be executed and you have to remember everything. Like this:
testData = nil
responseError = false
. . . make a request . . .
function didGetData(data, status, headers)
if status == 200 then
testData = data
else
responseError = true
end
end
function waitForData()
if testData ~= nil then
-- Data is here, do something with it
end
if responseError then
-- Bad response from http.request
end
end
Also, make sure to use 3 tilde characters at the start and end of code blocks in this forum, use the Preview button when in doubt.
And make sure that you don’t mix up names like “didGetData” and “getDidData” in your live code. Sometimes, a wrong name might go unnoticed.