Hi, I was wondering how to update a FloatingTextParticle...My code PHP: public function spawnFloats(Level $level, Vector3 $pos, array $texts){ $float = implode("\n", $texts); $float = str_replace("{MAX}", $this->getServer()->getMaxPlayers(), $float); $float = str_replace("{ONLINE}", count($this->getServer()->getOnlinePlayers()), $float); $float = str_replace("{TPS}", $this->getServer()->getTicksPerSecond(), $float); $float = str_replace("{MOTD}", $this->getServer()->getMotd(), $float); //$players = $this->getServer()->getOnlinePlayers(); $pp = new FloatingTextParticle($pos, C::AQUA.$float); $pp->setText(C::AQUA.$float); $level->addParticle($pp); return true; } This code works to spawn texts but when updating by using this function it spawns another text instead of editing existing one...Thanks for help Problem: I need to update the texts of floating particle
PHP: public function spawnFloats(Level $level, Vector3 $pos, array $texts){ $float = implode("\n", $texts); $float = str_replace("{MAX}", $this->getServer()->getMaxPlayers(), $float); $float = str_replace("{ONLINE}", count($this->getServer()->getOnlinePlayers()), $float); $float = str_replace("{TPS}", $this->getServer()->getTicksPerSecond(), $float); $float = str_replace("{MOTD}", $this->getServer()->getMotd(), $float); //$players = $this->getServer()->getOnlinePlayers(); $pp ?? $pp = new FloatingTextParticle($pos, "", ""); $pp->setText(C::AQUA.$float); $level->addParticle($pp); return true; }
It will simply add another particle instead of updating it (I think). And android Genisys app doesn't spawn multiple floating particles so if you tested there, it's a bad test
Save the FloatingTextParticle instance, don't create a new one, it will give you one with a new entity id (This is, what you don't want!) and just use $particle->setText() and $particle->setTitle() to edit the text.
Then save them all. You need them to have the same entity ids when you want to update them. Otherwise you will spawn new entities for the client. (Which should be your issue, right? New text spawned inside the already existing text.)
You may have already seen something like: PHP: $this->variable = 'example'; I believe you can also read a bit about this here. Correct me if I'm wrong. Also, you should be fine by storing it in an array.
You are wrong ._. I need to get entity ID Everytime I spawn one ...And I know how to store data...I just want to know how can I get floats entity Id if I use your method
I suggest you to save the FloatingTextParticle objects, because to get the entityId value you could be forced to create a new class which extends the FloatingTextParticle class and makes you able to get this value. You cannot get this without doing something similar, because it is a protected variable.
OnEnable: PHP: $this->particles = []; Add particle: PHP: $particle = new FloatingTextParticle($pos, "", ""); $particle->setText(C::AQUA.$float);$this->particles[$player] = $particle;$level->addParticle($particle, [$player]); Update it with: PHP: $this->particles[$player]->setText("blah");$level->addParticle($this->particles[$player], [$player]); Last time this was working on my server