http.Fetch problems

Hey there, I’m trying to get the string from a text file which is found on my webhost and set a variable as the string, then use the variable.

This works
[lua]
http.Fetch(“http://minicore.net/news.txt”,

function(body) 
	
	print(body) 
	
end, 

function(fail) 

	print("Failed to grab string" .. tostring(fail)) 
	
end

)

[/lua]

This works too
[lua]
http.Fetch(“http://minicore.net/news.txt”,

function(body) 

	body1 = body 
	
	print(body1) 
	
end, 

function(fail) 

	print("Failed to grab string" .. tostring(fail)) 
	
end

)
[/lua]

This however, does not work.

[lua]
http.Fetch( “http://www.minicore.net/news.txt”,

	function(body)
	
		body1 = body
		
	end,
	
	function(err)
	
		print(err)
		
	end

)
print(body1)
[/lua]

It prints nil.

I tried adding tostring, no use same thing.
Predefining body1 doesn’t solve it either, it just prints an empty string.
Anyone has any idea? Even the example on the wiki doesn’t work…

It’s because your print will run before http.Fetch has finished getting the content from the webpage.

Okay then what’s the usual time that it takes for the http.Fetch to get the content? I found no info on this whatsoever so I had to ask here

There is no usual time. It depends on the load of the webserver you’re trying to reach, the speed of the internet connection, and loads of other factors.
It’s simply finished when the callback function is executed, and you should finish your logic in that function. The joy of asynchronous programming.

-snip-

Got it to work, thanks!