Eldar Nezametdinov Eldar Nezametdinov - 5 months ago 50
Scala Question

How to add nested message into already created message ? (in Scala)

After adding nested message i recieve nested messages from main message and got nothing.

You can see it in logs: 1 and 2. Size of List 0 !

Any ideas?

message PacketPlayers
repeated PacketPlayer players = 1;

enter image description here


ScalaPB case classes are immutable. In your example, addPlayers would not modify the instance it's called on, but return a new instance of PacketPlayer that has the additional players.

It is possible to avoid mutable arrays and vars in constructing the new object. For example:

val players = onlinePlayers.keySet.map(makePacketPlayer)
val packetPlayers = PacketPlayers().withPlayers(players)