Not setting variable

I have a script that is meant to get data from a webpage



function LoadDeed(ply)
	function http_reply(contents)
		data_reply = string.Explode("|", contents)
		xCord = data_reply[2]
		yCord = data_reply[3]
		zCord = data_reply[4]
		
	end
	http.Get("http://127.0.0.1/realwar/retrievedata.php?auth=datanet_687_PI&con=mapdata&map=" .. tostring(game.GetMap()), "", http_reply)
	
	return xCord, yCord, zCord
end


It variables it is set to return aren’t, but they can be seen inside the http_reply function, how do I get the variables to be accessed outside of the function?

I wouldn’t declare a function inside of a function, it’s weird.

Try making two separate functions.

Declare them outside of the function:

[lua]
function LoadDeed(ply)
local xCord, yCord, zCord
function http_reply(contents)
data_reply = string.Explode("|", contents)
xCord = data_reply[2]
yCord = data_reply[3]
zCord = data_reply[4]

end
http.Get("http://127.0.0.1/realwar/retrievedata.php?auth=datanet_687_PI&con=mapdata&map=" .. tostring(game.GetMap()), "", http_reply)

return xCord, yCord, zCord

end
[/lua]

[lua]-- Or the more reliable way:

function LoadDeed(ply)
return http.Get(“http://127.0.0.1/realwar/retrievedata.php?auth=datanet_687_PI&con=mapdata&map=” … tostring(game.GetMap()), “”, function(contents)
local data_reply = string.Explode("|", contents)
local xCord = data_reply[2]
local yCord = data_reply[3]
local zCord = data_reply[4]
return xCord , yCord , zCord
end )
end
[/lua]

That should work, if http.Get returns the return of the callback (Which it really should)

Otherwise use locals like above.

It returns an HTTPConnection object:

That doesn’t work, I can’t seem to get the variables if they are outside the function, but can if they are outside.

Sorry for the bump, but I still can’t get this to work.

-snip- Wrong thread.

It takes some time for it to get the info from the website, but you instantly return the variables. There is a reason it takes a function as an argument.
AKA you’ll have to do whatever you need to do with those values inside the http_reply function.