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

Using GetProductInfo to check if Asset exists?

Asked by
Dummiez 360 Moderation Voter
10 years ago

Say if I wanted to retrieve all possible audio id's using a ridiculously long for loop, and used the GetProductInfo of the MarketplaceService.

wait()
for idAsset = 156000000, 131000000, -1 do -- Rough approx. of newest sound id to oldest sound id.
local curId = game:GetService("MarketplaceService"):GetProductInfo(idAsset)
    if curId then -- This id exists.
        print(curId.Name) -- Print the name of the sound.
    end
end

However, when it executes for the first time:

MarketplaceService:getProductInfo() failed because rawProductInfo was empty.

I can't check whether it is nil (or otherwise empty)?

3 answers

Log in to vote
1
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago

It'd be significantly faster to parse them out of the catalog. There are only ~34,000 audio.

Start with PageNumber=1 and work your way up.

http://www.roblox.com/catalog/json?Subcategory=16&CurrencyType=0&SortType=0&SortAggregation=3&SortCurrency=0&IncludeNotForSale=true&Category=9&PageNumber=1

0
Do you parse these with ContentProvider? I can see what you're going with here.. Dummiez 360 — 10y
Ad
Log in to vote
2
Answered by 10 years ago
wait()
for idAsset = 156000000, 131000000, -1 do -- Rough approx. of newest sound id to oldest sound id.
    local s, curId = pcall(function() return game:GetService("MarketplaceService"):GetProductInfo(idAsset) end)
    if s and curId then -- This id exists.
        print(curId.Name) -- Print the name of the sound.
    end
end

This should work. GetProductInfo errors if there is no asset with that ID. I would suggest adding waits if you experience latency.

0
I've added a print statement after 'do' and it is returning an output every 1/5th of a second. Not sure if pcall has a delay when resulting in an error? The loop appears to run as if there is a wait() statement added. Dummiez 360 — 10y
Log in to vote
-1
Answered by
jav2612 180
10 years ago

The method :GetProductInfo() returns a dictionary table that you can search through. It will not give you the results you're looking for if you just check to see if it exists or not. You should be able to check to see if certain things in this library are nil if it would not exist, such as when it was created or it's creator.

Try using this:

 wait()
for idAsset = 156000000, 131000000, -1 do -- Rough approx. of newest sound id to oldest sound id.
local curId = game:GetService("MarketplaceService"):GetProductInfo(idAsset)
    if curId.Created ~= "null" then -- This id exists.
        print(curId.Name) -- Print the name of the sound.
    end
end

0
That is optional. It is set 0 as default and this still returns the same error mentioned above. Dummiez 360 — 10y
0
Editted.... jav2612 180 — 10y

Answer this question