• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Comparing values returns unexpected value

Glovacky

New Member
Joined
Jun 22, 2013
Messages
8
Reaction score
0
Hi. Im trying to write a new script for upgrading an item.

I have this in my global.lua:
Code:
function getItemAttribute(uid, key)
   local i = ItemType(Item(uid):getId())
   local string_attributes = {
     [ITEM_ATTRIBUTE_NAME] = i:getName(),
     [ITEM_ATTRIBUTE_ARTICLE] = i:getArticle(),
     [ITEM_ATTRIBUTE_PLURALNAME] = i:getPluralName(),
     ["name"] = i:getName(),
     ["article"] = i:getArticle(),
     ["pluralname"] = i:getPluralName()
   }

   local numeric_attributes = {
     [ITEM_ATTRIBUTE_WEIGHT] = i:getWeight(),
     [ITEM_ATTRIBUTE_ATTACK] = i:getAttack(),
     [ITEM_ATTRIBUTE_DEFENSE] = i:getDefense(),
     [ITEM_ATTRIBUTE_EXTRADEFENSE] = i:getExtraDefense(),
     [ITEM_ATTRIBUTE_ARMOR] = i:getArmor(),
     [ITEM_ATTRIBUTE_HITCHANCE] = i:getHitChance(),
     [ITEM_ATTRIBUTE_SHOOTRANGE] = i:getShootRange(),
     ["weight"] = i:getWeight(),
     ["attack"] = i:getAttack(),
     ["defense"] = i:getDefense(),
     ["extradefense"] = i:getExtraDefense(),
     ["armor"] = i:getArmor(),
     ["hitchance"] = i:getHitChance(),
     ["shootrange"] = i:getShootRange()
   }
   
   local attr = Item(uid):getAttribute(key)
   if tonumber(attr) then
     if numeric_attributes[key] then
       return attr ~= 0 and attr or numeric_attributes[key]
     end
   else
     if string_attributes[key] then
       if attr == "" then
         return string_attributes[key]
       end
     end
   end
return attr
end

function doItemSetAttribute(uid, key, value)
   return Item(uid):setAttribute(key, value)
end

function doItemEraseAttribute(uid, key)
   return Item(uid):removeAttribute(key)
end

And this is my script attached to in-game item:
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    cid = player:getId()
    itemEx = target

    local it = ItemType(itemEx.itemid)
    local a = it.getName();
    local b = getItemAttribute(itemEx.uid, ITEM_ATTRIBUTE_NAME);
   
if( a ~= b )then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "item_attribute_name: "..getItemAttribute(itemEx.uid, ITEM_ATTRIBUTE_NAME))
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "item:getname: "..it:getName())

end

Everytime I use script it returns:

16:48 item_attribute_name: jacket
16:48 item:getname: jacket

Why does it happen? item attribute name and name seems to be the same, so why a~=b is true?
 
what tfs version?
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local it = ItemType(target.itemid)
    local a = it:getName()
    local b = target:getAttribute(ITEM_ATTRIBUTE_NAME)
    if a ~= b then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "item_attribute_name ->".. b)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "item:getname() -> ".. a)
    end
    return true
end
 
Back
Top