Quantcast Unique ID - ESOUI
Thread Tools Display Modes
11/14/17, 10:12 AM   #1
Join Date: Nov 2017
Posts: 3
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:
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.

  Reply With Quote
11/14/17, 10:46 AM   #2
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 1,768
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)
  3. -- Use this function to get unique hash key for a given id64.
  4. function zo_getSafeId64Key(id)
  5.         return Id64ToString(id)
  6. end

  Reply With Quote
11/14/17, 10:57 AM   #3
Join Date: Nov 2017
Posts: 3
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:
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",
  Reply With Quote
11/14/17, 11:22 AM   #4
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,127
Why not use a simple index which increments with each item added?
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
  Reply With Quote
11/14/17, 05:59 PM   #5
Join Date: Nov 2017
Posts: 3
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!
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Unique ID

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off