1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Chwecking NBT Value

Discussion in 'Development' started by Junkdude, May 18, 2017.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Say i wanted to check the value of a stringtag named haste and see if it's value was haste1, how would i check if its value is equal to haste1
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Muqsit's example.
     
    Muqsit likes this.
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    This doesnt solve the thread, this just shows me how to add it/check if it has that tag, i want to check the data/value of that tag
     
  4. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    That example does show you how to check the value of the tag, but anyway..
    PHP:
    /** @var Item $item */
    $haste $item->getNamedTag()["haste"];

    /** @var Tile|Entity $object */
    $haste $object->namedtag["haste"];
    You can also use
    PHP:
    /** @var CompoundTag $nbt */
    $haste $nbt->haste;
     
  6. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    shouldnt the second example solve it?
    if($test == 'instakill'){/*do stuff*/}elseif($test=='something else'){/*more stuff*/}
     
  7. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    I though it would be like this if($item->getNamedTag()->haste->getValue() === "haste1){
     
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You can use that too. And also
    PHP:
    if($item->getNamedTag()->haste === "haste1")
     
  9. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Ohh okay, that makes sense i guess, the way i tried didnt work. Probably the way i had it
     
  10. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    No didnt work
     
  11. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Use equal instead of identical operator if you want to use it that way. But the correct way would be to use
    PHP:
    /** @var Item $item */
    $item->getNamedTag()["haste"]
    //OR
    $item->getNamedTag()->haste->getValue()
     
    jasonwynn10 likes this.
  12. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Second method worked! Thanks Muq
     
    jasonwynn10 and Muqsit like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.