I have made a struct and want to read and edit the values in that struct in for loop
for that I have written this code
struct PlayerScores{
Name:String,
CurrentRoll:u8,
Total:u32,
}
If I have four players I want to insert the currentRoll in each iteration and add the currentROll to Total value of the struct.
Pleas can someone guide
// player_1 is an instance of PlayerScores
player1.current_roll = 5; // Sets the value of the current_roll field to 5
player1.total += 5; // Increments the value of the total field by 5
If you're looping over a Vec of PlayerScores or something similar, you will need to do for player in &mut your_vec or for player in your_vec.iter_mut() to get mutable access to the items.