Thread Tools Display Modes
02-18-12, 01:17 PM   #1
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Values in a table always strings?

Originally Posted by unlimit View Post
I created a table (??? think that's what it's called) named TRUESYS.MD, that will always have my metadata available.

I then have another function that runs to check if TRYESYS.MD[1] is greater than the current version of my package, and if so, empties the package then using RDXDB.SetPackageMetadata I reassign all of my metadata.

This doesn't seem to work for me, though. Do you see anything blatantly wrong, Sigg? I end up with no metadata at all after emptying the package, even after supposedly reassigning all of my metadata.

lua Code:
  1. TRUESYS.PKG = {
  2.     "true_core",
  3.     "true_unitframes",
  4.     "true_multiframes"
  5. };
  6.  
  7. TRUESYS.MD = {
  8.     "1.1",
  9.     "Unlimit",
  10.     "Demon Soul US",
  11.     "manversuspixel.com",
  12.     "(True) Adaptive User Interface",
  13.     "infoIsShare",
  14.     "infoIsImmutable",
  15.     "infoIsIndelible"
  16. };
  17.  
  18. RDXEvents:Bind("INIT_DATABASE_LOADED", nil, function()
  19.     if not RDXDB.GetPackage(TRUESYS.PKG[1]) then return nil; end
  20.     if not RDXDB.GetPackageMetadata(TRUESYS.PKG[1], "infoVersion") then return nil; end
  21.  
  22.     if RDXDB.GetPackageMetadata(TRUESYS.PKG[1], "infoVersion") < TRUESYS.MD[1] then
  23.         RDX.print("Updating (True) Adaptive User Interface to the latest version!");
  24.         for i=1,3 do
  25.             RDXDB._EmptyPackage(TRUESYS.PKG[i])
  26.             for g=1,9 do
  27.                 RDXDB.SetPackageMetadata(TRUESYS.PKG[i], TRUESYS.MD[g], true)
  28.             end
  29.         end
  30.     end
  31. end);
  32.  
  33. RDXEvents:Bind("INIT_DATABASE_LOADED", nil, function()
  34.     -- Define a local to package name and set package metadata
  35.     local core = RDXDB.GetOrCreatePackage(TRUESYS.PKG[1]);
  36.     local unitframes = RDXDB.GetOrCreatePackage(TRUESYS.PKG[2]);
  37.     local multiframes = RDXDB.GetOrCreatePackage(TRUESYS.PKG[3]);
  38.     for i=1,3 do
  39.         for g=1,9 do
  40.             RDXDB.SetPackageMetadata(TRUESYS.PKG[i], TRUESYS.MD[g], true)
  41.         end
  42.     end
  43.  
  44. -- Do stuff
  45.  
  46. end);
Originally Posted by sigg View Post
It is because "1.1" is a string.

I suggest that you use version 1, version 2 etc ....

By default, elements in your table are string.

Use the function:
local numb = tonumber(RDXDB.GetPackageMetadata(TRUESYS.PKG[1], "infoVersion"))

Cheers
The problem is, all of those objects in my table are strings, I guess? o.o Which isn't applicable? I'm not sure really what sigg means by using tonumber() as a function to correct the mistake, if someone would be so kind to explain. (I'd ask in the OpenRDX forums, but sigg is only usually on early in the morning. <.<)
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
02-18-12, 01:22 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
tonumber() takes a string and tries to convert it into a number type value. If it fails in doing this, it returns nil.

For example:
tonumber("1.1") returns the number 1.1
tonumber("unlimit") returns nil



A couple further notes, when you try to create a table with a name of TRUESYS.MD, it actually tries to index a table named TRUESYS and place the table in the field MD. This is because Lua handles "." as an "index of" operator. If the TRUESYS table doesn't exist, it'll throw an error.

The second note, it's perfectly ok to compare strings with <, > , and equivalent operators. This causes a comparison of each byte in the string rather than trying to convert them into numbers. This only works if you use both strings or both numbers as mixing data types in these comparisons would throw an error..

For example:
"1.0"<"1.1" returns true
"1.0"<1.1 errors
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 02-18-12 at 01:37 PM.
  Reply With Quote
02-18-12, 01:28 PM   #3
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Originally Posted by SDPhantom View Post
tonumber() takes a string and tries to convert it into a number type value. If it fails in doing this, it returns nil.

For example:
tonumber("1.1") returns the number 1.1
tonumber("unlimit") returns nil
So what he's saying is, I should use tonumber() for anything involving numbers when trying to place it into the metadata of my package?
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
02-18-12, 02:32 PM   #4
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Ah. No, the thing that was blatantly wrong was my use of RDXDB.SetPackageMetadata().

lua Code:
  1. TRUESYS.PKG = {
  2.     "true_core",
  3.     "true_unitframes",
  4.     "true_multiframes"
  5. };
  6.  
  7.     TRUESYS.MD = {
  8.     "1.1",                                              -- infoVersion
  9.     "Unlimit",                                          -- infoAuthor
  10.     "Demon Soul US",                                    -- infoRealm
  11.     "[email protected]",                                  -- infoAuthorEmail
  12.     "manversuspixel.com",                               -- infoAuthorWebsite
  13.     "(True) Adaptive User Interface",                   -- infoComment
  14.     "infoIsShare",
  15.     "infoIsImmutable",
  16.     "infoIsIndelible"
  17. };
  18.  
  19. RDXEvents:Bind("INIT_DATABASE_LOADED", nil, function()
  20.     local version = RDXDB.GetPackageMetadata(TRUESYS.PKG[1], "infoVersion")
  21.     local update
  22.  
  23.     if not RDXDB.GetPackage(TRUESYS.PKG[1]) then return nil; end
  24.     if not version or version < TRUESYS.MD[1] then update = true; end
  25.  
  26.     if update == true then
  27.         RDX.print("Updating (True) Adaptive User Interface to the latest version!");
  28.         for i=1,3 do
  29.             RDXDB._EmptyPackage(TRUESYS.PKG[i], true)
  30.             RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoVersion", TRUESYS.MD[1]);
  31.             RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoAuthor", TRUESYS.MD[2]);
  32.             RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoAuthorRealm", TRUESYS.MD[3]);
  33.             RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoAuthorEmail", TRUESYS.MD[4]);
  34.             RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoAuthorWebsite", TRUESYS.MD[5]);
  35.             RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoComment", TRUESYS.MD[6]);
  36.             RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoIsShare", TRUESYS.MD[7]);
  37.             RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoIsImmutable", TRUESYS.MD[8]);
  38.             RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoIsIndelible", TRUESYS.MD[9]);
  39.         end
  40.     else
  41.         RDX.print("(True) Adaptive user Interface is up to date!");
  42.     end
  43. end);
  44.  
  45. RDXEvents:Bind("INIT_DATABASE_LOADED", nil, function()
  46.     -- Define a local to package name and set package metadata
  47.     local core = RDXDB.GetOrCreatePackage(TRUESYS.PKG[1]);
  48.     local unitframes = RDXDB.GetOrCreatePackage(TRUESYS.PKG[2]);
  49.     local multiframes = RDXDB.GetOrCreatePackage(TRUESYS.PKG[3]);
  50.     for i=1,3 do
  51.         RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoVersion", TRUESYS.MD[1]);
  52.         RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoAuthor", TRUESYS.MD[2]);
  53.         RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoAuthorRealm", TRUESYS.MD[3]);
  54.         RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoAuthorEmail", TRUESYS.MD[4]);
  55.         RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoAuthorWebsite", TRUESYS.MD[5]);
  56.         RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoComment", TRUESYS.MD[6]);
  57.         RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoIsShare", TRUESYS.MD[7]);
  58.         RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoIsImmutable", TRUESYS.MD[8]);
  59.         RDXDB.SetPackageMetadata(TRUESYS.PKG[i], "infoIsIndelible", TRUESYS.MD[9]);
  60.     end
  61.  
  62.     -- do stuff
  63.  
  64. end);
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote

WoWInterface » Featured Projects » OpenRDX » OpenRDX Community » OpenRDX: Community Chat » Values in a table always strings?


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