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

The percentage ('%') symbol in a string.

Discussion in 'Development' started by Muqsit, Dec 10, 2016.

Thread Status:
Not open for further replies.
  1. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Hey,
    I wanted to use a percentage symbol in an item's name to determine a specific ratio.
    What I did was..
    PHP:
    $item->setCustomName($successTag.'% Success Rate');
    But it didn't work. The percentage symbol just wouldn't display when I am holding the item. It would only display the name with the percentage symbol when...
    • I would hover over the item while my inventory window was open (Windows 10).
    • Transfer it from one inventory to another (PocketEdition).
    Things I've tried:
    • Name it to '%% Success Rate'.
    • Use double quotes.
    • Save it as a variable, then call it in the setCustomName bit.
    • Tried the long way: Set custom name through NBT tags instead of setCustomName().
     
    jasonwynn10, Primus and SOFe like this.
  2. LilCrispy2o9

    LilCrispy2o9 Spider Jockey

    Messages:
    43
    GitHub:
    lilcrispy2o9
    Try putting a backslash in front of it.
     
    Muqsit likes this.
  3. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    That would work.. I assume he explained "%" in his code..
     
  4. Enes5519

    Enes5519 Spider Jockey

    Messages:
    28
    GitHub:
    Enes5519
    '%' => Use
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    None of them worked sadly. Screenshot_20161210-152242.png Screenshot_20161210-152250.png
     
    Skullex likes this.
  6. LilCrispy2o9

    LilCrispy2o9 Spider Jockey

    Messages:
    43
    GitHub:
    lilcrispy2o9
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Hmm...
     
    Muqsit likes this.
  8. LilCrispy2o9

    LilCrispy2o9 Spider Jockey

    Messages:
    43
    GitHub:
    lilcrispy2o9
    W
    Didn't see that lol
     
  9. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    But you said you "figured it out"? So did someone test wrongly?
     
    jasonwynn10 likes this.
  10. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Try doing:
    PHP:
    $item->setCustomName($successTag."\x25 Success Rate");
    NOTE: use double quotes.
     
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Using "\x25" is the same as using a literal "%". The % sign is not preprocessed in the code; it is preprocessed by either the client or by PocketMine before it is sent to the client. "\x25" and "%" are identical in code, and the same thing (byte 25) is passed to other parts in the code. Whatever the cause of the problem is, as long as it is not something with code preprocessing (and we are very sure it isn't), I'm afraid your suggestion is not going to solve any problems.
     
    jasonwynn10, Muqsit and Primus like this.
  12. LilCrispy2o9

    LilCrispy2o9 Spider Jockey

    Messages:
    43
    GitHub:
    lilcrispy2o9
    It works for me, I don't understand why it wouldn't for him
     
    Primus likes this.
  13. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    They won't lose anything if they just simply try it.
     
    Primus likes this.
  14. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    And I am telling you that I know it is the same before you even try it. Want a fight?
     
    Primus likes this.
  15. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Doesn't work. Already tested.

    Same error as before, nothing changed much. It won't display the symbol when the item is held, but displays when its hovered over (or in MCPE, when the item is transferred from one inventory to another).
    1.PNG scs.PNG
     
  16. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Did you try PlayerItemHeldEvent?
     
    Muqsit likes this.
  17. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Not sure, but maybe it helps when you do setiteminhand (or something like that) to update the item name in MCPE?
     
  18. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I'm not even using it. Why'd you need that anyways? Just give the player...
    PHP:
    $item Item::get(Item::DIAMOND_SWORD01)->setCustomName('Percentage symbol is %');
    The item doesn't need to be updated.
     
    jasonwynn10 likes this.
  19. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    But transferring the item to another player is also updating it, so I thought this could trigger it, too.
     
  20. Aviv

    Aviv Baby Zombie

    Messages:
    156
    might be mojang bug/client bug
     
Thread Status:
Not open for further replies.
  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.