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

How can I get the Texture ID from a Decal ID?

Asked by
nilVector 812 Moderation Voter
8 years ago

I know that you can already get the Texture ID from a Decal ID by subtracting the Decal ID by 1, however, sometimes, the Texture ID isn't necessarily one less than the Decal ID. Sometimes, there is a difference of two or even three. I am trying to create a way to detect what the difference would be.

Here's my scrap code. For the sake of testing, I purposely used a Decal ID whose Texture ID was not 1 less than it.

local difference = 1
local decalID = --[[User Given ID via GUI Input]]--

while "http://www.roblox.com/asset/?id="..(decalID - difference) == nil do
    difference = difference + 1
end

print(difference)
script.Parent.ImageLabel.Image = "http://www.roblox.com/asset/?id="..(decalID - difference)

The problem is in this line:

while "http://www.roblox.com/asset/?id="..(decalID - difference) == nil do

I'm checking to see if it's nil, but it still gives me an error and stops the script. I know it is wrong and technically it can't be nil since it is an existing value, but I don't know any other method of checking to see if it is a valid Texture.

I have also tried it like this:

while script.Parent.ImageLabel.Image == nil do
    difference = difference + 1
    script.Parent.ImageLabel.Image = "http://www.roblox.com/asset/?id="..(decalID - difference)
end

...and that also does not work.

Any ideas on how to do this?

1 answer

Log in to vote
1
Answered by 8 years ago

You will need to "tostring" the number, so:

while "http://www.roblox.com/asset/?id="..tostring(decalID - difference) == nil do

Without this, you are simply trying to add a number onto a string, and the error will be called.

With this though, it will always return true whilst in an "if" statement as you are not actually checking the Marketplace instance, just the text. I'd recommend looking into this:

http://wiki.roblox.com/index.php?title=API:Class/MarketplaceService/GetProductInfo

That should help you work your script out.

0
No, actually, you can concact a number with a string. Lua automatically tostrings it for you. Also, thank you for that link. nilVector 812 — 8y
0
Does it? Oh, thank you. I never knew that. darkelementallord 686 — 8y
Ad

Answer this question