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

Solved Question with new PocketMine

Discussion in 'Development' started by NidPlays, Feb 11, 2018.

  1. NidPlays

    NidPlays Creeper

    Messages:
    5
    When I updated to alpha 11 old method of setting nbt tag did not work.
    How do I set a String tag to an item?
    Also how do I check that tag?
     
  2. NidPlays

    NidPlays Creeper

    Messages:
    5
  3. NidPlays

    NidPlays Creeper

    Messages:
    5
    I'm trying to add a string tag and then check if that item has a string tag. After var_dump ing it I realized that it did not have the string tag. Also I assume that thread is outdated by now so need help with new api/methods
     
    Lewis Brindley likes this.
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    A better method is this:
    PHP:
    $nbt->setString("key here""value");
     
  5. NidPlays

    NidPlays Creeper

    Messages:
    5
    Thanks!
     
  6. SleepSpace9

    SleepSpace9 Slime

    Messages:
    78
    GitHub:
    sleepspace9
    Getting a value from a key is similar (requires to know that it's a String value):
    PHP:
    $nbt->getString("key here");
    To check if a key of the specified type exists and create it if not you can do:
    PHP:
    if(!$nbt->hasTag("key here"StringTag::class)) {
        
    $nbt->setString("key here""value");
    }
     
    jasonwynn10, Kenn Fatt and NidPlays like this.
  7. NidPlays

    NidPlays Creeper

    Messages:
    5
    Thank you both.
     
  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.