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

Solved How do I update floating text?

Discussion in 'Development' started by rektpixel, Jan 22, 2018.

  1. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    I have this code:
    PHP:
        public function onInteract(PlayerInteractEvent $event){
            
    $player $event->getPlayer();
            
    $block $event->getBlock();
            
    $level $this->getServer()->getDefaultLevel();
            if(
    $block->getId() == 46) {
                if(
    $this->mode>=0&&$this->mode<=1000) {
                    
    $this->mode++;
                    
    $this->text = new FloatingTextParticle(new Vector3(7748, -892), "");
                    
    $this->text->setText("§bYour score: §6" $this->mode "");
                    
    $level->addParticle($this->text);
                }
            }
        }
    }
    The problem with this is that the floating text dose not update.. it just spawns another floating text. how can I just make it update the text?
     
  2. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    solved it myself before a reply. there's no point deleting this, I'll leave it here in case anyone has this problem in the future. fix:
    onEnable:
    PHP:
    $this->text = new FloatingTextParticle(new Vector3(7748, -892), """");
    onInteract:
    PHP:
        public function onInteract(PlayerInteractEvent $event){
            
    $player $event->getPlayer();
            
    $block $event->getBlock();
            
    $level $this->getServer()->getDefaultLevel();
            if(
    $block->getId() == 46) {
                if(
    $this->mode>=0&&$this->mode<=1000) {
                    
    $this->mode++;
                    
    $this->text->setText("§bYour score: §6" $this->mode "");
                    
    $level->addParticle($this->text);

                }
            }
        }
    }
     
  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.