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

Solved Adding multiple lines to Floating Text

Discussion in 'Development' started by RekkuzaRage, Jan 20, 2019.

  1. RekkuzaRage

    RekkuzaRage Spider

    Messages:
    7
    On my journey to create a floating text particle plugin, I noticed that you can set title and text with setTitle and setText methods, but I'm trying set multiple lines (more than 2 basically). I assumed "\n" would break the line, but it doesn't break or add another line when using setText. So, my question is, how can this be achieved?
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    \n should work. Does it output as just \n, or does it not show up at all? Can I see how you used it?
     
  3. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    If you've already spawned the floating text, and then try using setText, you'll have to use level->addparticle again with the update object for it to show up.
     
  4. RekkuzaRage

    RekkuzaRage Spider

    Messages:
    7
    First of all, I save the particle data within a JSON file.
    Code:
    {
        "test-particle": {
            "pos": [
                299.3842,
                100.91329999999999,
                -82.5187,
                "world"
            ],
            "title": "\u00a7l\u00a7eTest",
            "text": "\u00a77It is supposed to break here\nbut it does not",
        }
    }
    Then, I create the floating text particle and save it into an array using the loadConfiguration method
    Code:
    private function loadConfigurations() {
            if(file_exists($this->plugin->getDataFolder() . "particle.json")) {
                $particleConfig = new Config($this->plugin->getDataFolder() . "particle.json", Config::JSON);
                foreach($particleConfig->getAll() as $k => $v) {
                    $level = $this->server->getLevelByName($v["pos"][3]);
                    $position = new Position($v["pos"][0], $v["pos"][1], $v["pos"][2], $level);
                    $levelName = $v["pos"][3];
                    $this->particle[$levelName][$k] = new FloatingTextParticle($position, $v["text"], $v["title"]);
                }
            }
        }
    Then, when the player actually views the particle it shows "\n" as string and doesn't break the line. It could be due to the json format? I'm not really sure.


    [​IMG]
    [​IMG]
     
    Last edited: Jan 20, 2019
  5. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Try a second \ in front of \n, so it looks like \\n. JSON is apparently weird with newlines.
     
  6. RekkuzaRage

    RekkuzaRage Spider

    Messages:
    7
    It definitely is odd. I tried the double slash, but still nothing. I even changed the format to YAML, it doesn't break it either.

    Code:
    YAML format
    ---
    default-tag:
      pos:
      - 321
      - 101
      - -83
      - world
      title: title-example
      text: Floating Text \nUmmmm no
    ...
     
  7. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    Not 100% sure with this but try searching the string and replacing it with PHP_EOL
    Edit: replacing the "\n" with PHP_EOL
     
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    That's YAML for you!
    Code:
    text: line1\nline2
    
    will render as
    Code:
    line1\nline2
    ----
    Code:
    text: "line1\nline2"
    
    will render as
    Code:
    line1
    line2
     
    RekkuzaRage and corytortoise 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.