Issue With Shared.SendHTTPRequest
<div class="IPBDescription">Executes backwards!??</div>So i have this code:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
...... (more code above) .......
local steamId = client:GetUserId()
local temp = 3
local test = 1
Shared.SendHTTPRequest("http://www.blabla.com/testpage.php?id="..tostring(steamId), "GET", function(response)
if response then
Shared.Message("Is Authorized.")
Shared.Message("Response is "..response)
temp = tonumber(response)
Shared.Message("Answer in function is "..temp)
else
Shared.Message("Is NOT Authorized.")
end
end)
test = temp
Shared.Message("test out of http request is "..test)
return test
... (do other things with test) ...<!--c2--></div><!--ec2-->
The page it pulls just returns a simple number, in this case 19.
Whenever it executes this code however, this is what i get:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->test out of http request is 3
Is Authorized.
Response is 19
temp in function is 19<!--c2--></div><!--ec2-->
It looks like it executes backwards... it seems to ignore SendHTTPRequest and its code until after it returns test variable!
Can someone please give me a hand to manage to assign that http response to the test variable? In my head this makes 0 sense...
Thanks in advance!
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
...... (more code above) .......
local steamId = client:GetUserId()
local temp = 3
local test = 1
Shared.SendHTTPRequest("http://www.blabla.com/testpage.php?id="..tostring(steamId), "GET", function(response)
if response then
Shared.Message("Is Authorized.")
Shared.Message("Response is "..response)
temp = tonumber(response)
Shared.Message("Answer in function is "..temp)
else
Shared.Message("Is NOT Authorized.")
end
end)
test = temp
Shared.Message("test out of http request is "..test)
return test
... (do other things with test) ...<!--c2--></div><!--ec2-->
The page it pulls just returns a simple number, in this case 19.
Whenever it executes this code however, this is what i get:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->test out of http request is 3
Is Authorized.
Response is 19
temp in function is 19<!--c2--></div><!--ec2-->
It looks like it executes backwards... it seems to ignore SendHTTPRequest and its code until after it returns test variable!
Can someone please give me a hand to manage to assign that http response to the test variable? In my head this makes 0 sense...
Thanks in advance!
Comments
Once a response is received it runs that function you set.
Well the problem is that i need to use this inside the function.
The function is like this:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function setValue(ns2id):
local temp
if (condition a) -> check web site response (with ns2id argument) and assign it to temp.
else if (condition b) -> assign X value to temp
else -> assign Y value to temp
return temp<!--c2--></div><!--ec2-->
This function setValue MUST return the web site response when "condition a" is met.
Some might suggest to run the web site response outside the function and store it in a variable ahead of time. I would love to, but the script parses certain variables to setValue that are used in the html query.
Anyone have any idea how to accomplish this?
I even tried this:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->*temp and test variables defined somewhere up here*
local function setResponse(response)
temp = response
end
local function callPage()
Shared.SendHTTPRequest("http://www.blah.org/blah.php?id=blah", "GET", setResponse)
end
local function importantFunction(blah)
callPage()
test = temp
return test
end<!--c2--></div><!--ec2-->
and off course this didn't work either... **rips last 3 hairs off the head**
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->if condition == a then
Shared.SendHTTPRequest("http://www.blah.org/blah.php?id=blah", "GET", function(response)
DoSomething(response)
end)
else
DoSomething(defaultValue)
end<!--c2--></div><!--ec2-->