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

Solved Separate a number

Discussion in 'Plugin Help' started by ItsInspire, Jan 3, 2021.

  1. ItsInspire

    ItsInspire Silverfish

    Messages:
    15
    GitHub:
    itsinspire
    Hello, I'm making a plugin that displays a players kills in a rainbow format behind the player name and the question is How do I separate a 4 digit integer so that I can make a rainbow format? Example:

    Number: 4000
    $player->sendMessage(TextFormat::RED.$number1.TextFormat::ORANGE.$number2.TextFormat::YELLOW.$number3.TextFormat::LIME.$number4);

    If anyone has a idea, Please let me know. I'm just learning pocketmine so idk

    Here is a image of what I wanted it to look like:
     

    Attached Files:

  2. RicardoMilos384

    RicardoMilos384 Slime

    Messages:
    82
    GitHub:
    ricardomilos384
    PHP:
    $number 4000;
    $n_str = (string) $number;
    $number1 $n_str[0];
    $number2 $n_str[1];
    $number3 $n_str[2];
    $number4 $n_str[3];
     
    xSoapers likes this.
  3. ItsInspire

    ItsInspire Silverfish

    Messages:
    15
    GitHub:
    itsinspire
    [20:42:36] [Server thread/CRITICAL]: ParseError: "syntax error, unexpected '$number' (T_VARIABLE)" (EXCEPTION) in "plugins/TestPL/src/ItsInspire/TestPL/Main" at line 53
     
  4. ItsInspire

    ItsInspire Silverfish

    Messages:
    15
    GitHub:
    itsinspire
    Nevermind, It's a type error. This works
     
  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.