Welcome to the Achaea Forums! Please be sure to read the Forum Rules.

Capitalising table entries

XliXli Posts: 354Member ✭✭✭ - Distinguished
I am using a script at the moment which compares what's in the room with a list of viable targets, but there's some inconstancy with capitalisation (Elder instead of elder, etc) in the GMCP data. I was wondering if there was a way to auto-capitalise everything when assigning to a table...

Here's a snippet of the script:

autotarget.here = autotarget.here or {}

function autotargetHereAdd()

if gmcp.Char.Items.Add.location == "room" then

table.insert(autotarget.here, gmcp.Char.Items.Add.item)

end

end


I have tried using :title() around gmcp.Char.Items.Add.item to no avail. Will I need to loop through my table and update each entry?

Hiroma tells you, "I just got to listen to someone complain about your deadly axekick being the bane of their existence."
Archdragon Mizik Corten, Herald of Ruin says, "Man, that was a big axk."
Hellrazor Cain de Soulis, Sartan's Hammer says, "Your [sic] a beast."
Tagged:

Comments

  • EldEld Posts: 3,946Member @@ - Legendary Achaean
    gmcp.Char.Items.Add.item is a table, not a string, so the string.title() function won't work with it. If you wanted to get the appropriate name with the first letter capitalised, you'd need to use gmcp.Char.Items.Add.item.name:title(). If the only problem with the inconsistent capitalisation is in comparing strings, you could always just make the two strings you're comparing all lower case to do the comparison, like
       if string1:lower() == string2:lower() then ...

    Otherwise, I'm not sure why the capitalisation matters.
    NizarisValden
  • NizarisNizaris The Holy City of MhaldorPosts: 537Member ✭✭✭✭✭ - Grand Achaean
    What @Eld said. I personally use string:upper() everywhere for string comparison. You don't need to capitalize what's in the database, just add a :lower() or :upper() call to the function in question, and you are set.
    image
  • XliXli Posts: 354Member ✭✭✭ - Distinguished
    Thanks all for your advice, I have tweaked my scripts to force everything to lower before comparing, seems to be working now...
    Hiroma tells you, "I just got to listen to someone complain about your deadly axekick being the bane of their existence."
    Archdragon Mizik Corten, Herald of Ruin says, "Man, that was a big axk."
    Hellrazor Cain de Soulis, Sartan's Hammer says, "Your [sic] a beast."
Sign In to Comment.