#runInterval Not Working?

1 messages · Page 1 of 1 (latest)

harsh rampart
#

Im getting the error:
[Scripting][error]-Plugin [TPRP Vanilla+ Behavior Pack - 0.0.1] - [Teams.js] ran with error: [TypeError: not a function at <anonymous> (Teams.js:34)]

And here is the code that it errored on

System.runInterval(() => { Teams(); }, 1); //This is line 34)

System.runInterval(() => {
    World.sendMessage("This is an interval run " + " sending a message every 30 seconds.");
}, 600);

That block at the bottom is taken straight from the microsoft docs and when I put that in front of the one that is running what Im trying to do, it instead throws an error at the microsoft example, was there any updates to runInterval that were not noted in the docs?

rapid ferry
#

it might be in the teams function

harsh rampart
#
import { System } from "@minecraft/server";
import { World } from "@minecraft/server";

void function Teams(){
    for (const player of World.getPlayers()) {
        const team = player.getTags().find(tag => tag.startsWith(`t-`)) || ``;


        //Determines Nametag Color
        let color;
        const red = '§c';
        const blue = '§b';

        switch (team) {
            case "t-TPRP":
                color = red;
                break;
            case "t-AWAY":
                color = blue;
                break;
            default:
                color = ``; // none
                break;
        }

        // Sets the team name to not include the "t-" which tells this processor that its a team tag
        const teamDisplay = team.replace('t-', '');
        // Combine rank, newline character, team color, and player name
        player.nameTag = color + teamDisplay + "\n" + player.name;
    }
};


system.runInterval(() => { Teams(); }, 1);

system.runInterval(() => {
    World.sendMessage("This is an interval run " + " sending a message every 30 seconds.");
}, 600);
#

Ive considered that but also the MS example doesnt deal with the teams function and it throws the error too

rapid ferry
harsh rampart
#

kk

#

ok that looks like it fixed the not a function issue

#

now its saying that Teams() is not defined

rapid ferry
harsh rampart
#

kk

#

issue fixed, now to grab another device and see if the script works correctly

#

welp it for the most part worked, I now need to figure out how to get the section sign character working, since it kept throwing UTF-8 errors last time I put it directly in my code

#

Im gonna void cluttering the forum with another thread, so I will just ask the UTF-8 question here

#

so whenever I have the section sign (§) in the script, Minecraft throws an error saying its an invalid UTF-8 sequence, any ideas on how to fix that?

harsh rampart