• 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!

[TFS 1.1] Trouble adding new attributes [Solved]

Acedayz

Member
Joined
Jan 24, 2015
Messages
38
Reaction score
19
What I've had trouble with is this:
Code:
inline static bool isIntAttrType(itemAttrTypes type) {
    return (type & 0x7FFE13) != 0;
}
inline static bool isStrAttrType(itemAttrTypes type) {
    return (type & 0x1EC) != 0;
}

So I tried to figure out why my attributes wouldn't work, and this what I've done:

Found out the values:
0x7FFE13 = 8388115
0x1EC = 492

Looked at the last attribute value: (unchanged)
ITEM_ATTRIBUTE_DOORID = 4194304
4194304 * 2 = 8388608
8388608 - 492 = 8388116
8388116 - 1 = 0x7FFE13

So what I did was to take my last custom attribute's value:
ITEM_ATTRIBUTE_TEST9 = 2147483648

And did the same math as above which gave me the value 0xFFFFFE13.
So I changed it to this:
Code:
inline static bool isIntAttrType(itemAttrTypes type) {
    return (type & 0xFFFFFE13) != 0;
}


This made item:getAttribute(ITEM_ATTRIBUTE_TEST9) work, but not my item:getTest9() function.
Code:
int32_t LuaScriptInterface::luaItemGetTest9(lua_State* L)
{
    // item:getTest9()
    Item* item = getUserdata<Item>(L, 1);
    if (item) {
        lua_pushnumber(L, item->getTest9());
    }
    else {
        lua_pushnil(L);
    }
    return 1;
}

Code:
int8_t getTest9() const {
    if (hasAttribute(ITEM_ATTRIBUTE_TEST9)) {
        return getIntAttr(ITEM_ATTRIBUTE_TEST9);
    }
    return items[id].test9;
}

Which makes me think the next problem is with this function:
Code:
inline static bool isStrAttrType(itemAttrTypes type) {
    return (type & 0x1EC) != 0;
}

I can't figure out where the number 492(0x1EC) is coming from, so this is where I'd like some help.
getTest9() works for getting the value of the item type, but not the item attribute.

I may be doing this completely wrong and would like some help to actually understand what these functions does.

Thank you!

EDIT:
Ok, nevermind.
There were no more problems with those functions, just another little mistake as usual.
 
Last edited:
read about bit flags and bit operators,
0x1EC is combination of all string attribute flags like ITEM_ATTRIBUTE_TEXT,ITEM_ATTRIBUTE_WRITER
0xFFFFFE13 is combination of all integer attribute flags
 
Back
Top