C
C#2y ago
joshua1n

❔ How would I go about looping through a json file and search for the highest value in a category?

🙂
3 Replies
joshua1n
joshua1nOP2y ago
I know how to pull the values but not sure how I would compare all the values
timer.Repeat(10f, 0, () =>
{
foreach(BasePlayer player in BasePlayer.activePlayerList)
{
string playerID = player.userID.ToString();
string playerStatsJson = dataFile[playerID] as string;
Stats playerStats = JsonConvert.DeserializeObject<Stats>(playerStatsJson);

int kills = playerStats.kills;

if (player kills > * other player kills)
{
// code here
}
}
});
timer.Repeat(10f, 0, () =>
{
foreach(BasePlayer player in BasePlayer.activePlayerList)
{
string playerID = player.userID.ToString();
string playerStatsJson = dataFile[playerID] as string;
Stats playerStats = JsonConvert.DeserializeObject<Stats>(playerStatsJson);

int kills = playerStats.kills;

if (player kills > * other player kills)
{
// code here
}
}
});
Angius
Angius2y ago
LINQ would probably be the easiest .MaxBy(...) for example Or .OrderBy(...).First() for older versions of .NET
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server