ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Unique ID (https://www.esoui.com/forums/showthread.php?t=7466)

gamemodul 11/14/17 10:12 AM

Unique ID
 
Hello everyone

Is there a specific function to create an unique ID? The ID could be a string, integer or float. Can work with all of that. It just should be unique over time. As far as I've searched the web, LUA doesn't provide a "get unique" function like other languages.

How I'm doing it now:
Code:

a unique ID per day: os.date('D%Y%m%d')
a unique ID over time: string.format('T%s:%s', os.time(), os.rawclock())

Also seen the ESO API functions GetGameTimeMilliseconds() and GetFrameTimeSeconds() but I think it wouldn't make a difference if I don't replace os.rawclock() with it.


Thanks
gamemodul

Baertram 11/14/17 10:46 AM

Do you need the id based on an item ingame or just without any relevance to the items (I guess so as you wrote "over time unique").

If you have an item relevance you could use:


Lua Code:
  1. GetItemUniqueId(bag, slot)
  2.  
  3. -- Use this function to get unique hash key for a given id64.
  4. function zo_getSafeId64Key(id)
  5.         return Id64ToString(id)
  6. end

http://www.esoui.com/forums/showthre...ghlight=unique

gamemodul 11/14/17 10:57 AM

Hi Baertram

Yes, don't need an Item related ID.

Basically I'm adding items to a table. The key constructed with os.time() inside allows me to parse the items ordered by time (also saves an extra value inside the item itself). Adding that os.rawclock() because that might be the most unique thing that I can get if items where added really fast.

Like this:
Code:

sometable = {
    ["D20171114"] =
    {
        ["T1510677345:358673"] = "8217,8215,2,1",
        ["T1510677322:336346"] = "8248,8254,-6,64",
        ["T1510677322:336140"] = "8254,8257,-3,64",
        ["T1510677330:343808"] = "8214,8211,3,1",
        ["T1510677322:335642"] = "8257,8267,-10,64",
        ["T1510677332:346033"] = "8215,8214,1,1",
        ["T1510677322:336460"] = "8247,8248,-1,64",
        ["T1510677323:336834"] = "8245,8247,-2,64",
        ["T1510677323:336931"] = "8211,8245,-34,64",
    },
    ...,
    ...
}


sirinsidiator 11/14/17 11:22 AM

Why not use a simple index which increments with each item added?

gamemodul 11/14/17 05:59 PM

Because... too easy! Just kidding ;)
That was how I first did it. Before I started to overthink things I guess. The more I think about the thing now, the more I think that's the way to go again. The time can be easily added as value so it doesn't get lost and my script doesn't read these keys anymore. So... ye, thank you guys for the input!


All times are GMT -6. The time now is 09:19 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI