获取玩家的名称以及玩家内部包含的数据该怎么做?

huangapple go评论174阅读模式
英文:

How do I get the name of the players and the data contained inside the players?

问题

I'm new to Javascript and jQuery and I'm trying to make an in game scoreboard for Rocket League and ran into some trouble.

Here is the console log of data from the game:
获取玩家的名称以及玩家内部包含的数据该怎么做?

I'm trying to access the stats like boost contained inside the players, however, but I don't really want to change the player's names in the code every time to access it.

I was able to access the team scores by doing this

$(".scorebug .team.left .score").text(d['game']['teams'][0]['score']);

but for the players, I tried doing something like

$(".scorebug .playernames .playerBlue1").text(d['players'].child());

and

$(".scorebug .playernames .playerBlue1").text(d['players'].next());

but it doesn't work.

Is there a way I can select Buzz_2, Foamer_5, Heater_6, Outlaw_1, Sundown_3, and Tex_7 without having to type their names in the code every time? Thanks!

英文:

I'm new to Javascript and jQuery and I'm trying to make an in game scoreboard for Rocket League and ran into some trouble.

Here is the console log of data from the game:
获取玩家的名称以及玩家内部包含的数据该怎么做?

I'm trying to access the stats like boost contained inside the players, however, but I don't really want to change the player's names in the code every time to access it.

I was able to access the team scores by doing this

$(".scorebug .team.left .score").text(d['game']['teams'][0]['score']);

but for the players, I tried doing something like

$(".scorebug .playernames .playerBlue1").text(d['players'].child());

and

$(".scorebug .playernames .playerBlue1").text(d['players'].next());

but it doesn't work.

Is there a way I can select Buzz_2, Foamer_5, Heater_6, Outlaw_1, Sundown_3 and Tex_7 without having to type their names in the code every time? Thanks!

答案1

得分: 0

如果您只想按数据中的顺序获取球员的统计信息,您可以使用JavaScript的for...in循环来遍历它们。

您想要对这些分数做什么?您想要将它们记录到控制台吗?还是想要将它们保存到变量或数组以供以后使用?

如果您只想将它们记录下来,您可以这样简单做:

for (let player in data.players) {
    let playerBoostStat = data.players[player].boost;
    console.log(player + ' has a boost of ' + playerBoostStat);
}

这将记录一个句子,其中包括每个球员的姓名和相应的提升统计信息。

英文:

If you just want to get the players stats in the order they appear in the data, you can simply loop through them with JavaScript's for...in loop.

What do you want to do with these scores? Do you want to log them to your console? Or do you want to save them to variables or an array for later use?

If you just want to log them, you could do something as simple as

for (let player in data.players) {
    let playerBoostStat = data.players[player].boost
    console.log(player + ' has a boost of ' + playerBoostStat)
}

That will log a sentence exclaiming each player's name and respective boost stat.

huangapple
  • 本文由 发表于 2023年3月7日 12:17:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658012.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定