content/hifi-content/DomainContent/Event/Scripts/avatarCounterClientScript_js.js
2022-02-13 22:49:05 +01:00

27 lines
No EOL
979 B
JavaScript

//
// avatarCounterClientScript.js
//
// This script counts the avatasr in a domain and displays the number on a given text entity.
// For best result, make sure that only one client is running this script.
//
// Created by Faye Li on 3 Feb 2017.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
// Replace the ID here with the text entity's ID in your domain
var textEntityID = "{6dd27786-0cca-4e8d-adb2-f54b4218a899}";
var INTERVAL_MS = 1000; // in ms, how often do we recount avatars
var intervalID = Script.setInterval(function() {
var avatarCount = AvatarList.getAvatarIdentifiers().length;
Entities.editEntity(textEntityID, {text: avatarCount});
}, INTERVAL_MS);
function cleanup() {
Script.clearInterval(intervalID);
}
Script.scriptEnding.connect(cleanup);
}());