Thread Tools Display Modes
04/15/14, 01:42 AM   #1
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 626
Question in regards to string.lower

Code:
function Harvest.IsValidBottle(name)
    for k, v in pairs(Harvest.bottle) do
		d("v name :" .. v)
		d("name :" .. name)
        if v == name then
            return true
        end
    end

    return false
end
I though the above function was working perfectly yesterday. However, I reverted changes to stick with the original authors syntax.
The entire function:
Warning: Spoiler

Code:
_, _, _, itemId = ZO_LinkHandler_ParseLink( objectName ) --name, color, type, id, +19 other attributes
He uses that to do something and I don't quite get. The function is on the wiki but no explanation as to what it does. Whatever it's doing it's preventing the routine from comparing the names. So I changed the Boolean routine to this thinking it would be enough.
Code:
function Harvest.IsValidBottle(name)
    for k, v in pairs(Harvest.bottle) do
		d("v name :" .. v)
		d("name :" .. string.lower(name))
        if v == string.lower(name) then
            return true
        end
    end

    return false
end
When I do that then the debug routine returns this.
Code:
:hFFFFFF:item:1187:1:13:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:hclear waterh
I fixed it by making a global variable. However, for my sanity does anyone know why that's happening?
  Reply With Quote
04/15/14, 06:33 AM   #2
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Sharlikran View Post
When I do that then the debug routine returns this.
Code:
:hFFFFFF:item:1187:1:13:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:hclear waterh
This is broken item link. If you use string.lower() on item link, function ZO_LinkHandler_ParseLink does not work.

Warning: Spoiler

Last edited by Garkin : 04/15/14 at 06:42 AM. Reason: Added info.
  Reply With Quote
04/15/14, 09:03 AM   #3
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 626
I received a nice PM from ins as well. Thanks ins. He suggested the same thing that that it may have changed since beta. I have a question though. The above code snipit suggests using text, color, zo_strsplit(':', data) The original routine has "_, _, _, itemId = ZO_LinkHandler_ParseLink( objectName )"

To me, not understanding lua all that much, means that ZO_LinkHandler_ParseLink (onjectname) is assigining 4 variables. The first three are "_, _, _," and the fourth is itemID. I have seen some routines that say things like, 'for _, node in pairs( nodes ) do'. What does '_' that mean? Nil?
  Reply With Quote
04/15/14, 09:31 AM   #4
Stormknight
 
Stormknight's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 128
http://mirven.github.io/underscore.lua/

Kinda mentions it. I'd be interested to know why it should be used though.

It *seems* like it's a local throwaway variable?

Kinda like each function automatically has "local _" declared at the start?
  Reply With Quote
04/15/14, 10:31 AM   #5
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Sharlikran View Post
What does '_' that mean? Nil?
"_" is dummy variable - http://www.lua.org/pil/5.2.html
  Reply With Quote
04/15/14, 01:55 PM   #6
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Sharlikran View Post
Code:
function Harvest.IsValidBottle(name)
    for k, v in pairs(Harvest.bottle) do
		d("v name :" .. v)
		d("name :" .. string.lower(name))
        if v == string.lower(name) then
            return true
        end
    end

    return false
end
When I do that then the debug routine returns this.
Code:
:hFFFFFF:item:1187:1:13:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:hclear waterh
I fixed it by making a global variable. However, for my sanity does anyone know why that's happening?
Because the item link contains more than the name and if you turn the H into an h, it no longer is a correct item link, as a H is expected to start the color code, not a h.


And no, there is no workaround, because even if you manage to not convert the Hs, in the end your strlower will wreck havoc upon the item name once you have UTF-8 characters in it.

Last edited by Iyanga : 04/15/14 at 02:00 PM.
  Reply With Quote
04/15/14, 04:14 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
_ is just as valid a variable name as x, or myVar, or THIS_AWESOME_VARIABLE_NAME.

It is used conventionally as a throwaway variable by many authors, assigning it to values we don't care about. Since we don't care about them, it doesn't matter if they get overwritten. It is good practice to declare this _ variable as local.
  Reply With Quote
04/15/14, 05:14 PM   #8
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 626
Originally Posted by Iyanga View Post
Because the item link contains more than the name and if you turn the H into an h, it no longer is a correct item link, as a H is expected to start the color code, not a h.

And no, there is no workaround, because even if you manage to not convert the Hs, in the end your strlower will wreck havoc upon the item name once you have UTF-8 characters in it.
Yeah but since I am learning how all this works I am printing out every little piece of information. When the name of the item is displayed, it's lower case, yet it's mixed case in other places. So It's messing up comparing the string. At least that's what I think is happening, I'm still testing that. I didn't know that OnLootUpdate was passing the whole Item link until I started reading the responses.

I made "ZO_LinkHandler_ParseLink( objectName )" assign all 22 variables and it's still assigning the same information.

1: The item name
2: The color. Which is 3 bytes in Hex like ffffff or 2DC50E
3: The type: so far a string 'item' for what I have tested with.
4: The ItemId
5: Unknown, but it's 13 for most of what I have seen.

Then +18 other attributes which are usually 0.

Request, I need a routine to break #5 into flags. Can anyone help me with that?

Such that it displays:

{0x0001} 'Unknown1'
{0x0002} 'Unknown2'
{0x0004} 'Unknown3'
{0x0008} 'Unknown4'
{0x0010} 'Unknown5'
{0x0020} 'Unknown6'
{0x0040} 'Unknown7'
{0x0080} 'Unknown8'

I don't need the number in brackets, that's for clarification.

Last edited by Sharlikran : 04/15/14 at 05:22 PM.
  Reply With Quote
04/15/14, 05:50 PM   #9
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
During my testing of my gatherer addon I have noticed a pattern to the case differences.

Nodes ( Iron Ore, Jute, Maple ) etc. Are harvestable fixed objects in the game. Items ( iron ore, raw jute, maple) are the items you receive by harvesting from them.

So far, it has consistently been, objects = mix case, items = lower case. This means that they can be stored in the same table, with apparently the same key values and me treated differently.

EG.

Harvests[zone][node] = Nodes that were harvested. ( Harvests["Auridon"]["Iron Ore"] )
Harvests[zone][item] = Items harvested from nodes. ( Harvests["Auridon"]["iron ore"] )

That bit of information aside ...

If the item link is anything remotely like the ones in wow you will probably find that they will be markers such as quality, type, filterType, enchants, traits etc.

To figure them out look at multiple items with identical stats, and then ones with 1 or 2 different but the same in themselves. Ultimately you will see a bigger picture there.
  Reply With Quote
04/15/14, 06:25 PM   #10
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 626
Thanks for sharing that. I mean this wholeheartedly, in that proper variable naming is important. I think I see a lot of things with variables like 'item', rather then 'NodeName', 'NodeNumber', 'ItemName', 'ItemNumber' and so on. I'll have to review that and the API Functions to make sure I'm really evaluating things correctly.

I'll have to look at the API functions a little closer, because I want the None Numbers and the Node Names, not Item Numbers and Item Names.

Last edited by Sharlikran : 04/15/14 at 06:30 PM.
  Reply With Quote
04/15/14, 08:19 PM   #11
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
There are no node numbers. The node information you get from the interaction functions. But interactions are only tracked via an Update routine. There are no events currently at least that track interactions. A sample of my update routine that checks for interaction follows. But please note that I have noticed some flaws in the interaction results resulting in several checks before processing the information as valid.

Lua Code:
  1. local playerInteracting = IsPlayerInteractingWithObject()
  2.  
  3. local interactMode = GetInteractionType()
  4. if interactMode ~= INTERACTION_HARVEST then processingHarvest = false return end
  5. processingHarvest = true
  6.  
  7. local action, name, blocked, extra, context = GetGameCameraInteractableActionInfo()

For say a mine (Iron Ore) the action would be "Mine" and the name would be "Iron Ore".
For a tree limb ( Maple ) the action would be "Cut" and the name would be "Maple".
For most others it is "Collect" or "Gather".

Occasionally however, I have had the "Use" of a crafting station show up as INTERACTION_HARVEST instead of a more appropriate interaction.
  Reply With Quote
04/16/14, 09:36 AM   #12
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 626
Warning: Spoiler

I have a rather complex way of figuring out what the player is doing. The only routine I have not figured out is, "function Harvest.HarvestProvisioning()" I made that to track when a player is using the provisioning station. However, it doesn't fire at that time, nor does it fire when looting a Barrel. I don't use function Harvest.ValidCraftingType() yet because I'm not sure what the constants apply to.

I have other complex ways to check if the type of the item is invalid based on the Node Name. However it's not refined yet and still needs a lot of work. The basic idea is that I use the ID Numbers from Esohead and some Node Names. Shinni mentioned that using names may not be a good idea since they may change, however, these are basic names like Barrel, Crate, so they shouldn't change.

Also I am looking into using GetLootTargetInfo() InteractTargetType and GetLootItemLink.

Last edited by Sharlikran : 04/16/14 at 02:29 PM.
  Reply With Quote
04/16/14, 11:22 PM   #13
ins
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 76
Some extra info on the Linkhandler Parselink on items.

Example:
Code:
[[|H3A92FF:item:45147:04:16:26582:4:16:0:0:0:0:0:0:0:0:0:9:0:0:0:0|hhide boots of magicka^p|h]], 
[[|H3A92FF:item:45147:04:12:26580:4:12:0:0:0:0:0:0:0:0:0:4:0:0:0:0|hrawhide boots of health^p|h]],
1. Name
2. Colour
3. "item" type(?)
4. ItemID
5. unknown (Could be related to item Quality-ish, See 3 on Green items, 4-11 on Blue, 49 on Named, 50 on Unique)
6. LEVEL Requirement (Verified)
7. Related to enchant (Type) (Verified)
8. Related to Enchant (Strength) (Verified)
9. Related to Enchant (Strenght) (Verified)
10
11
12
13
14
15
16
17
18
19. Style (Verified) (34= Imperial)
20
21. Bound or not (1 if bound) (Verified)
22 CHARGES on Weapon (Verified)
23

For 7 and 8.
Note; Items with "#5 "Qualityish" at 50=> Named item will not show anything in 7-8. Also you can not enchant these items.)

1. [[|H2DC50E:item:54512: 3:23:45871:3:23:0:0:0:0:0:0:0:0:0: 1:0:0:0:0|hamethyst necklace of reduce feat cost^n|h]]
2. [[|H2DC50E:item:54512: 3:23:26847:2:19:0:0:0:0:0:0:0:0:0: 1:0:0:0:0|hamethyst necklace of disease resist^n|h]]
3. [[|H2DC50E:item:54512: 3:23:26847:2:22:0:0:0:0:0:0:0:0:0: 1:0:0:0:0|hamethyst necklace of disease resist^n|h]]
1 = Reduce Feat Cost Stamina Cost
2 = Disease Resist (95 disease resist, a 15-25 ench)
3 = Disease Resist (110 disease resist, a 20-30 enchant)
45871 - Reduce Feat Cost

26847 - Disease Resist
26578 - REduce Targets Armor by xx for xx seconds
26579 - Adds XX Max Stamina
26580 - Adds Health
26581 - Adds Health Recovery
26582 - Adds Magicka
26583 - Adds Magicka REcovery
26586 - Adds Poison Resistance
26587 - Deals Poison Damage
26588 - Adds Stamina
26589 - Adds Stamina Recovery
26590 - Vampire Slaying (Deals x fire damage to vampires)
26591 - Reduce targets Power by xx for xx seconds

5365 - Adds Frost Damage
26844 - Adds Shock Damage
26848 - Adds Flame Damage

For 19 and 21 see example below:

[[|H3A92FF:item:45150:4:15:26580:4:15:0:0:0:0:0:0:0:0:0: 9:0:0:0:0|hrawhide guards of health^p|h]],
[[|H3A92FF:item:45150:4:15:26580:4:15:0:0:0:0:0:0:0:0:0:34:0:1:0:0|hrawhide guards of health^p|h]],
The second "item" is the same, except it has been converted to Imperial Style, and is now bound to the player.


Weapon damage SCALES depending on the "LEVEL" Requirement (#6)

Last edited by ins : 04/17/14 at 12:30 AM.
  Reply With Quote
04/17/14, 03:04 AM   #14
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 626
I did some more testing using the lootindex that is passed to GetLootItemLink() for ZO_LinkHandler_ParseLink. I had the most reliable results, consistently, without UI Exceptions, when I used the following two functions.

Code:
local _, _, itemType, itemId = ZO_LinkHandler_ParseLink( GetLootItemLink(lootindex) )
local TargetNodeName, TargetInteractionType, TargetActionName = GetLootTargetInfo()
Those gave consistent, usable information to determine what the player is doing. In earlier posts I mentioned using string.lower to normalize the case in the name. That is not needed if you use the above two lines. You will get all the info you need from those commands.

Granted I am curious about writing a separate lua file to add to HarvestMap that parses the Item link, to use ins' new found information. Aside from that, I think I can finally determine what is happening with the player, and how I am going to handle it.
  Reply With Quote
04/17/14, 05:47 AM   #15
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by ins View Post
Some extra info on the Linkhandler Parselink on items.

1. Name
2. Colour
3. "item" type(?)
...
3 is link type
ITEM_LINK_TYPE = "item"
ACHIEVEMENT_LINK_TYPE = "achievement"
CHARACTER_LINK_TYPE = "character"
CHANNEL_LINK_TYPE = "channel"
BOOK_LINK_TYPE = "book"
DISPLAY_NAME_LINK_TYPE = "display"
URL_LINK_TYPE = "url"
  Reply With Quote
04/17/14, 04:30 PM   #16
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
You're awesome, ins. I had noticed a few things in there (level, itemID, and what changed with an enchant), but you've discovered more than me.

It would also be really nice to build a table of enchant IDs.
  Reply With Quote
04/20/14, 12:54 PM   #17
ins
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 76
Added my first Wiki Entry. Probably not following any formatting guidelines though.

http://wiki.esoui.com/ZO_LinkHandler_CreateLink
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Question in regards to string.lower

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