Using hash_to_hex() to produce a unique id

I have items of a specific type and an index unique within that type. The type is a hash.

Will the code below produce a unique ID for that item? If not, what’s the best way of doing this?

local id = hash_to_hex(type).."_"..index

I think it helps to know what the id’s are used for?

I have a bunch of progress bars all using a module dealing with the gui side of things. The progress bars are divided into groups, each group shows at different times, but all live in the same collection.

The progress bar lua module is generic and doesn’t separate the progress bars into groups. I’d like a way to use unique ids with this module, so it can remain oblivious as to how these bars are grouped.

If the strings spat back by hash_to_hex() are not unique, my worry is that the ids produced might not be either.

If you ignore the hash_to_hex() function and start by asking yourself if a combination of type and index will give you a unique id? If the answer is yes, then using hash_to_hex() on the type will also produce a unique id. The only purpose of the function is to convert a value of type hash to a hexadecimal string.

2 Likes

It is yes! Bingo, then I should be good. Thanks!

1 Like