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

C++ Does not show the Text when the value is 0

Fabi Marzan

Well-Known Member
Joined
Aug 31, 2020
Messages
135
Solutions
6
Reaction score
67
Greetings as always, I have a problem that does not show the text when the value of the attribute is 0, I added the Tier attribute in the items, but apparently when I set it to 0, it does not show me the Tier text.

Add in sources in item.ccp
Lua:
        // Show Classification and Tier on item
        uint32_t classification = item ? item->getClassification() : it.classification;
        uint32_t tier = item ? item->getTier() : it.tier;
          
        if (classification) {
            s << "\nClassification: " << classification;
        }
      
        if (tier) {
            if (tier >= 0) {
                s << " Tier " << tier;
            }
        }

But when placing in attribute
Code:
 <attribute key="tier" value="0"/>

Basically does not show the text
image_2023-07-21_234944871.png

Just so you know, if it works if I put it in 1 or another number
1689997916277.png
Any idea what it could be? I would be grateful for the help

EDIT:
In fact, I put it like this:
Lua:
        // Show Classification and Tier on item
        uint32_t classification = item ? item->getClassification() : it.classification;
        uint32_t tier = item ? item->getTier() : it.tier;
          
        if (classification) {
            s << "\nClassification: " << classification;
        }
      
        if (tier >= 0) {
            s << " Tier: " << tier;
        }

But then it shows me on all items, when they don't even have the attribute
 
Last edited:
Solution
this way will never works,
you are declaring a int with bool value..
uint32_t tier = item->getTier() >= 0;
UINT32 = (VALUE >= 0) =>> VALUE >= 0 = TRUE or FALSE / 1 or 0
Post automatically merged:

check again what i've sent to you, and also, show what i've asked then i can help u further
Hmm, I don't quite understand what you mean, but I already chose the easiest way, what I did was place it in the same classification text, if the item has a classification then it will also get Tier.
Lua:
// Show Classification and Tier on item
uint32_t classification = item ? item->getClassification() : it.classification;
uint32_t tier = item ? item->getTier() : it.tier;
            
if (classification) {
    s << "\nClassification: " << classification <<...
maybe parsing from xml has condition "if higher than 0"
In fact I have doubts about that, because when I set the Arm attribute to 0, it also does not show the text

C++:
        if (tier) {
            s << " Tier " << tier;
        }
I also tried before that way and nothing does not show it.


EDIT:
In fact, I put it like this:
Lua:
        // Show Classification and Tier on item
        uint32_t classification = item ? item->getClassification() : it.classification;
        uint32_t tier = item ? item->getTier() : it.tier;
           
        if (classification) {
            s << "\nClassification: " << classification;
        }
       
        if (tier >= 0) {
            s << " Tier: " << tier;
        }

But then it shows me on all items, when they don't even have the attribute
 
Last edited:
Try -1 instead of 0 in getTier func in item.cpp file
C++:
uint8_t getTier() const {
            if (!hasAttribute(ItemAttribute_t::TIER)) {
                return -1;
            }

            auto tier = getAttribute<uint8_t>(ItemAttribute_t::TIER);
            if (tier > g_configManager().getNumber(FORGE_MAX_ITEM_TIER)) {
                SPDLOG_ERROR("{} - Item {} have a wrong tier {}", __FUNCTION__, getName(), tier);
                return 0;
            }

            return tier;
        }
 
You have a simple “truthy” check, zero is “falsy” so it won’t pass that check, try changing to (if “no value” is equal null):
C++:
if (value != nullptr) {
    ...
}
But in this case it’s uint32_t that is 0 in this case.

Or if it’s as posted above that no value is always -1 change check to:

C++:
if (value >= 0) {
    ...
}

// Edit: didn’t noticed that it was posted but message was removed, but I’ afraid attributes are checked with simple bitwise-and so you wont be able to distinguish 0 with not set (with hasAttribute), but try debug if there’s a diff between unset and 0
 
Last edited:
Try -1 instead of 0 in getTier func in item.cpp file
C++:
uint8_t getTier() const {
            if (!hasAttribute(ItemAttribute_t::TIER)) {
                return -1;
            }

            auto tier = getAttribute<uint8_t>(ItemAttribute_t::TIER);
            if (tier > g_configManager().getNumber(FORGE_MAX_ITEM_TIER)) {
                SPDLOG_ERROR("{} - Item {} have a wrong tier {}", __FUNCTION__, getName(), tier);
                return 0;
            }

            return tier;
        }
In fact I tried -1 and nothing... and is that code from canary? I'm sorry I didn't say the version, I'm using a tfs 1.5 nekiro

You have a simple “truthy” check, zero is “falsy” so it won’t pass that check, try changing to (if “no value” is equal null):
C++:
if (value != nullptr) {
    ...
}
But in this case it’s uint32_t that is 0 in this case.

Or if it’s as posted above that no value is always -1 change check to:

C++:
if (value >= 0) {
    ...
}

// Edit: didn’t noticed that it was posted but message was removed, but I’ afraid attributes are checked with simple bitwise-and so you wont be able to distinguish 0 with not set (with hasAttribute), but try debug if there’s a diff between unset and 0
put it like this:
Lua:
if (tier != nullptr) {
    s << " Tier: " << tier;
}

And there is an error when compiling:
Screenshot_3.png

And I've also tried before placing >= -1 as tier and it doesn't work either, it doesn't show the text, in fact it doesn't show it even though I have it in attribute 1.

To be clear, when I set it to -0 or 0, it shows Tier 0 on items, but what happens is that it shows it on all items when they don't even have the attribute put in item.xml.
Code:
<attribute key="tier" value="0"/>
 
In fact I tried -1 and nothing... and is that code from canary? I'm sorry I didn't say the version, I'm using a tfs 1.5 nekiro


put it like this:
Lua:
if (tier != nullptr) {
    s << " Tier: " << tier;
}

And there is an error when compiling:
View attachment 76930

And I've also tried before placing >= -1 as tier and it doesn't work either, it doesn't show the text, in fact it doesn't show it even though I have it in attribute 1.

To be clear, when I set it to -0 or 0, it shows Tier 0 on items, but what happens is that it shows it on all items when they don't even have the attribute put in item.xml.
Code:
<attribute key="tier" value="0"/>
show how u are parsing this attribute when loading items.xml
and how you have made your getTier function..

Post automatically merged:

my idea is:
if item doesnt have key tier, then tier = -1 (it would be the default value on the struct of itemType)
if item have key tier, then tier = the value u've set.
then on your 'get description' u gonna do:

C++:
        // Show Classification and Tier on item
        uint32_t classification = item ? item->getClassification() : it.classification;
        uint32_t tier = item->getTier();
          
        if (classification) {
            s << "\nClassification: " << classification;
        }
      
        if (tier >= 0) {
            s << " Tier " << tier;
        }
 
Last edited:
show how u are parsing this attribute when loading items.xml
and how you have made your getTier function..

Post automatically merged:

my idea is:
if item doesnt have key tier, then tier = -1 (it would be the default value on the struct of itemType)
if item have key tier, then tier = the value u've set.
then on your 'get description' u gonna do:

C++:
        // Show Classification and Tier on item
        uint32_t classification = item ? item->getClassification() : it.classification;
        uint32_t tier = item->getTier();
         
        if (classification) {
            s << "\nClassification: " << classification;
        }
     
        if (tier >= 0) {
            s << " Tier " << tier;
        }
I put it like this:
Lua:
<item id="3286" article="a" name="mace">
        <attribute key="weaponType" value="club"/>
        <attribute key="attack" value="16"/>
        <attribute key="defense" value="11"/>
        <attribute key="weight" value="3800"/>
        <attribute key="classification" value="1"/>
        <attribute key="tier" value="0"/>
</item>

if i put:
uint32_t tier = item->getTier() >= 0;

For example put it like this:
Code:
uint32_t tier = item->getTier() >= 0;
if (tier) {
    s << " Tier: " << tier;
}

They appear in all the items and it shows me as Tier: 1, when I have it in tier: 0 in attribute

The problem seems to be with the value 0, as the other person explained, when it is value 0 it does not recognize the getTier() function and it is placed in all the items and not only those that have the attribute that comes from getTier():

Item.h
Code:
uint32_t getTier() const {
    if (hasAttribute(ITEM_ATTRIBUTE_TIER)) {
        return getIntAttr(ITEM_ATTRIBUTE_TIER);
    }
    return items[id].tier;
}
 
I put it like this:
Lua:
<item id="3286" article="a" name="mace">
        <attribute key="weaponType" value="club"/>
        <attribute key="attack" value="16"/>
        <attribute key="defense" value="11"/>
        <attribute key="weight" value="3800"/>
        <attribute key="classification" value="1"/>
        <attribute key="tier" value="0"/>
</item>

if i put:
uint32_t tier = item->getTier() >= 0;

For example put it like this:
Code:
uint32_t tier = item->getTier() >= 0;
if (tier) {
    s << " Tier: " << tier;
}

They appear in all the items and it shows me as Tier: 1, when I have it in tier: 0 in attribute

The problem seems to be with the value 0, as the other person explained, when it is value 0 it does not recognize the getTier() function and it is placed in all the items and not only those that have the attribute that comes from getTier():

Item.h
Code:
uint32_t getTier() const {
    if (hasAttribute(ITEM_ATTRIBUTE_TIER)) {
        return getIntAttr(ITEM_ATTRIBUTE_TIER);
    }
    return items[id].tier;
}
this way will never works,
you are declaring a int with bool value..
uint32_t tier = item->getTier() >= 0;
UINT32 = (VALUE >= 0) =>> VALUE >= 0 = TRUE or FALSE / 1 or 0
Post automatically merged:

check again what i've sent to you, and also, show what i've asked then i can help u further
 
this way will never works,
you are declaring a int with bool value..
uint32_t tier = item->getTier() >= 0;
UINT32 = (VALUE >= 0) =>> VALUE >= 0 = TRUE or FALSE / 1 or 0
Post automatically merged:

check again what i've sent to you, and also, show what i've asked then i can help u further
Hmm, I don't quite understand what you mean, but I already chose the easiest way, what I did was place it in the same classification text, if the item has a classification then it will also get Tier.
Lua:
// Show Classification and Tier on item
uint32_t classification = item ? item->getClassification() : it.classification;
uint32_t tier = item ? item->getTier() : it.tier;
            
if (classification) {
    s << "\nClassification: " << classification << " Tier: " << tier;
}

That already solved the problem for me for the moment. Thanks for the helps.
 
Solution
This system is very interesting, it reminded me of that Mir4 game. Could you explain to me how to add this system to the source step by step? For example, a "Golden Armor Tier 0" and "Golden Armor Tier 1" armor and so on?
 
Back
Top