我一直在尝试为我玩的在线IO游戏创建一个javascript,该JavaScript会在调用时向我显示封闭玩家的统计信息,但不会在hud聊天框中显示/添加信息为innerHTML。任何人都知道我该如何解决甚至可以改善它的想法?
注意:它将控制台日志播放器信息/统计信息,但不能用作HTMl。
function getPlayersStats() {
var entities = Game.currentGame.world.entities;
for (var uid in entities) {
if (!entities.hasOwnProperty(uid)) continue;
var players = entities[uid].targetTick;
if (players.entityClass == "PlayerEntity") {
var PlayersInfo = "[ " + players.name + " ] [ <b>Gold:</b> " + Math.round(players.gold) + " ]<br>[ <b>Wood:</b> " + Math.round(players.wood) + " ] [ <b>Stone:</b> " + Math.round(players.stone) + " ]<br>[ <b>Tokens</b> " + players.token + " ] [ <b>Uid</b> " + players.uid + " ]";
console.log(PlayersInfo)
document.getElementsByClassName("hud-chat-messages")[0].innerHTML += "<div class=\"hud-chat-message\"><hr>" + PlayersInfo + "</div>";
}
}
}
html代码:
<div id="hud-chat" class="hud-chat">
<input type="text" name="message" class="hud-chat-input" placeholder="Enter your chat message...">
<div class="hud-chat-messages">
</div>
</div>