I created a room. Now, how do I get its roomid?

0 votes
In my game user can create a room and then share the roomid with friends for them being able to join the room. Once a room is created I want to display the roomid so that the user can share it. There is NO callback that returns the roomid. How do I get it?
asked Sep 1, 2019 in Announcements by Ishan Gupta (10 points)

2 Answers

0 votes
Hi Ishan,

Greetings!!!

We have forwarded your query to our team we will get back to you as soon as possible.

Regards,

Priyanka Singh

App42 Team
answered Sep 3, 2019 by anonymous
When I use the following function,

public void onCreateRoomDone(RoomEvent eventObj)
{
            string roomID = eventObj.getData().getId();
}

I get a NullReferenceException.
Also, when using this statement, the connection state is always 1. I check it abundantly.
But when I remove this statement the connection state goes to 0 but what's the point of it then?


When I use the following code:

public void onCreateRoomDone(RoomEvent eventObj)
{
            //Statement doesn't give any error or exception.
            RoomData rd = eventObj.getData();

            //Prints 'com.shephertz.app42.gaming.multiplayer.client.events.RoomData' ???
            Debug.Log(rd);

            //GIVES NullReferenceException
            string roomID = rd.getId();
}
0 votes

I know this is a little late. But what I did, was I used a property as a key. 

Dictionary<string, object> dict = new Dictionary<string, object>();
dict.Add("CODE", randS);
MyClient.CreateRoom(name, owner, maxUsers, dict);
 
As you can see, I used a dictionary to add a CODE key. 
 
Next I used the next line to search for rooms with specific propetys, aka which for now would only be CODE. 
 
MyClient.GetRoomWithProperties(dict);
 
Now you can use a ZoneRequestListener to get the actual room id. Below is a onGetMatchedRoomsDone method. This is run whenever GetRoomWithProperties is run. I used a bunch of comments to explain the below code more
 
public void onGetMatchedRoomsDone(MatchedRoomsEvent matchedRoomsEvent)
            {
                RoomData[] rdArr = matchedRoomsEvent.getRoomsData(); //return the data of all the rooms
                if (rdArr.Length > 0) //if the array is longer than 1 we found at least one room
                {
                    Console.WriteLine("Found rooms");
                    String roomID = rdArr[0].getId(); //I'm still early in development, so for now I'm just assuming I got one room.
                    //You could check here to see if you got more than one room which in that case throw an error or something. 
                    WarpClient.GetInstance().JoinRoom(roomID); //Now you can join the room based on the ID.
                }
                else
                {
                    Console.WriteLine("Can't find rooms"); 
                }
            }

I hope this helps, it's been over a year since OP asked, so maybe someone else who needs help will stumble upon this. I'm pretty new to App warp, so there may definetly be a better way to do this.  

answered Dec 29, 2020 by ferritna (11 points)
Also quick comment, it takes a little bit for the onGetMatchedRoomsDone method to run. I used some Thread.Sleep() to allow the function to catch up to my client. You could probably use some event handler stuff as well.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...