I’m trying to hold a lobby system inside of a dictionary.
private Dictionary<string, Dictionary<string, string>> lobbys;
The first string being the Lobby ID, and the dictionary within the dictionary holding the clients usernames in the lobby.
When I try to create a new ‘lobby’ in the dictionary like so:
lobbys.Add("dSd244SfasdD", null);
( the “dSd244SfasdD” being the unique lobby ID, and null being the null dictionary I’ve yet to create (since theres no users in it yet))
I get this error: “Object referenced not set to an instance of an object.”
I’m unsure as to what I’m doing wrong, and I’m fairly new to C#. Please help. Thanks 🙂
You must first instantiate the lobbys Dictionary (which holds the Dictionaries):
Then you can add to this lobbys, and when you do so, you should instantiate those inner dictionaries.
Then, when you add to those inner dictionaries: