Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Trying To Understand HttpService?

Asked by
Vezious 310 Moderation Voter
8 years ago

What is wrong with this? I'm trying to get a table from Here

local Http = game:GetService("HttpService")
local Data = Http:GetAsync("http://pastebin.com/raw.php?i=ci5YECCB",true)
if Data.Cake == false then
print"Nope"
end

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

Essentially, that HTTP GET request returns, explicitly:

Data = [[{
["Cake"] = false,
["Pie"] = true,
}]]

On its own, this is just a string, not a table like you expect. There are two methods to get around this.

The first, loadstring, is not available in LocalScripts, and many features become disabled if you enable loadstring in Scripts, but is by far the simpler:

loadstring(Data)() -- The first parentheses create the function that contains the string interpreted as Lua code. the second call that function.

The second, which also is not available in LocalScripts for obvious reasons, is to fomat the text you want to load using JSON, and use HTTPService:JSONDecode to convert it to a Lua table. Technically, this will only work using Tables, and I haven't tested but I don't believe you can store functions even as members of Tables using this method.

Ad

Answer this question