I've never had the chance to use coroutines in lua, and as an amateur novice programmer, I'm not entirely sure of how they work but generally have a vague idea of the advantages from a brief talk with a friend. I've been attempting to use lua socket to pull information from a website for the purposes of finding out what organization a player is in and group them into it. The code I came up with does what is intended and works as follows:
The thing about this though, is that it hangs while getting the information. I discussed this with a friend, and he mentioned that this may be exacerbated if the host was experiencing problems. He mentioned that to remove the hang, I would have to use a non-blocking method and utilize coroutines. I've tried a few things, but they did not seem to work at all. I've done searches and fail to really understand the code presented.
How would I take advantage of coroutines to speed this up?
I would show my previous attempts at using connect and receive, but I scrapped them out of frustration.
function getorg(player)
local w = assert(http.request("http://www.ironrealms.com/game/honors/Lusternia/"..player))
if not w then
ui.alert("There has been an error retrieving information from the website.")
if IsConnected() then SendNoEcho("") end
return
end
local m = core.match("(?:City|Commune)\: ([A-Z][a-z]+)", w)
if not m then
ui.message("This person appears to either be a rogue, or not exist at all.")
if IsConnected() then SendNoEcho("") end
return
end
add_name(player, m[1])
if IsConnected() then SendNoEcho("") end
end
The thing about this though, is that it hangs while getting the information. I discussed this with a friend, and he mentioned that this may be exacerbated if the host was experiencing problems. He mentioned that to remove the hang, I would have to use a non-blocking method and utilize coroutines. I've tried a few things, but they did not seem to work at all. I've done searches and fail to really understand the code presented.
How would I take advantage of coroutines to speed this up?
I would show my previous attempts at using connect and receive, but I scrapped them out of frustration.