-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Garry's Mod example - needs synchronization #2
Comments
Thanks for the contribution! FiveM & this proposed addition are going to need a way to sychronize this with script execution, since the HTTP request handlers run asynchronously. @Yogpod if you are able to adapt your code to synchronize properly, that would be appreciated. Although, for both FiveM & Garry's Mod, PRs are welcome to fix this behavior. |
There is no way to run HTTP synchronously, so you'd have to shove the script as a function into the success/failed callback and that may mess with something/not be possible at all. |
It could be possible with coroutines |
Something like Something like coroutine.wrap(function()
local co = coroutine.running()
local code = ""
timer.Simple(0, function()
HTTP({
success = function(c, body, headers)
code = c
coroutine.resume(co)
end,
failure = function()
error("failed")
end,
method = "GET",
url = "https://raw.githubusercontent.com/Luraph/macrosdk/main/luraphsdk.lua"
})
end)
coroutine.yield()
if code then
RunString(code)
end
end)()
Github is messing with my code block for some reason |
@Yogpod You have to put the start and ending code block characters on their own line. Does that code work for you? |
No it does not work nevermind it was piggybacking off my previous execution |
@Yogpod remove the coroutine.wrap and move the code inside the function passed as an argument to coroutine.wrap into the top-level. Please let me know if it works or provide me any error messages you receive. |
timer is because http library isn't always ready
https://wiki.facepunch.com/gmod/Global.HTTP
Could also use CompileString instead of RunString but the source didn't seem to matter to you for the other examples.
The text was updated successfully, but these errors were encountered: