How to return values from a function callbacks

How do you return values from a function call back like http.Fetch

I need to get players profile url and put it on some derma

function getProfile(steamID)

steamID = util.SteamIDTo64(steamID)

local api_key = "[INSERT KEY HERE]"
local profile_url = ""

local url = profile_url..api_key.."&steamids="..tostring(steamID).."format=json"

local profile = {} -- profile created here

	function(contents, size)

		contents = util.JSONToTable(contents)
		profile.url = contents['response']['players'][1]['profileurl'] -- creatingn profile.url

		chat.AddText(profile.url) -- prints url of profile




chat.AddText(tostring(profile.url)) -- nil value for some reason

return profile -- returns nil value


can never get it to return a value as every variable created in the callback function seems to be destroyed as it leaves the callback function

Callback isn’t called until the request is done. You print profile.url and return profile long before .url has been set by the callback.

Is there anyway to return profile right after the callback has completed other then using a timer?

returning profile inside the callback function dosen’t work either.

It depends what you’re trying to do with the value.

If you want a derma label to display the url, set the text to “Loading…”, then in the callback set the text to the url.

Never thought about that.