Why is this printing out one value for each table and how do I fix it?
It's just printing:
http://roproxy.tk/catalog/json?Keyword=DJ Earworm&Category=9&ResultsPerPage=2
1: table: 1CFE5280
Audio
2: table: 1CFE56A0
Audio
When it should be printing:
1: table: 1CFE5280
Audio
187411559
DJ Earworm
and the same of the second table.
Table1:
[{"AssetId":187411559,"Name":"DJ Earworm - Summermash 120 seconds","Description":"Audio","Url":"/DJ-Earworm-Summermash-120-seconds-item?id=187411559","PriceInRobux":"","PriceInTickets":"","Updated":"1 month ago","Favorited":"1 time","Sales":"23","Remaining":"","Creator":"FireFume","CreatorUrl":"/User.aspx?ID=30719032","PrivateSales":"","PriceView":0,"BestPrice":"","ContentRatingTypeID":0,"AssetTypeID":3,"CreatorID":30719032,"CreatedDate":"\/Date(1416187543210)\/","UpdatedDate":"\/Date(1416187543223)\/","IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"MinimumMembershipLevel":0}
Table2:
{"AssetId":162880181,"Name":"DJ Earworm - Mash Up for What ","Description":"Audio","Url":"/DJ-Earworm-Mash-Up-for-What-item?id=162880181","PriceInRobux":"","PriceInTickets":"","Updated":"6 months ago","Favorited":"2 times","Sales":"67","Remaining":"","Creator":"tigerwhit4","CreatorUrl":"/User.aspx?ID=40632244","PrivateSales":"","PriceView":0,"BestPrice":"","ContentRatingTypeID":0,"AssetTypeID":3,"CreatorID":40632244,"CreatedDate":"\/Date(1403570650790)\/","UpdatedDate":"\/Date(1403570667263)\/","IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"MinimumMembershipLevel":0}]
Script:
function GetValues(Table) for i,v in pairs (Table) do for _,k in pairs (v) do return k end end end Module = require(script.Parent) Assets = Module.SearchCatalog("DJ Earworm","Audio",2) for i,v in pairs(Assets) do print(i..": ",v) print(GetValues(Assets)) end
Module:
local module = {} ------------------------------------------------------- function FindIndex(Table,Value) for i,v in pairs (Table) do if v == Value then return i end end end ------------------------------------------------------- module.SearchCatalog = function (Keyword,Catergory,ResultsPerPage) CatergoryTable = {"Revelance","Hats","TShirts","Packages","Gear","Models","Plugins","Decals","Audio"} local Service=game:GetService('HttpService') Url='http://roproxy.tk/catalog/json?Keyword='..Keyword..'&Category='..FindIndex(CatergoryTable,Catergory)..'&ResultsPerPage='..ResultsPerPage print(Url) WebRequest = Service:GetAsync(Url, true) AssetsTable = Service:JSONDecode(WebRequest) --for i,v in pairs(AssetsTable) do return AssetsTable -- end end ------------------------------------------------------- return module
I'm sorry but that was quite a mess, I rewrote it.
categories = {Revelance = 1, Hats = 2, TShirts = 3, Packages = 4, Gear = 5 , Models = 6, Plugins = 7, Decals = 8, Audio = 9} function searchCatalog(keyword, category, resultsPerPage) assert(categories[category], "Invalid category") local http = game:GetService("HttpService") local url = ("http://roproxy.tk/catalog/json?Keyword=%s&Category=%d&ResultsPerPage=%d"):format( keyword, categories[category], resultsPerPage) return http:JSONDecode(http:GetAsync(url, true)) end for k, v in next, searchCatalog("DJ Earworm", "Audio", 2) do print(k..":", v) print(v["AssetId"]) end