Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Fewpwew130 · Oct 27, 2015 at 08:39 PM · arraylistprogrammingcustomvalue

[common programming question] Custom array returns nothing

Hello dear community!

I’ve been trying to solve a problem of getting a list of active servers (rooms) and displaying them to the player. I am using Photon Unity free extension. Their code library and API are quite detailed, I tried to follow strictly, but I still don’t know why it works incorrectly. Could you have a look?

Their API says to use “static RoomInfo [] PhotonNetwork.GetRoomList()”, which I do. And it gets called correctly. But the value it returns– is nothing. It doesn’t say anything. Not “null”, not “0” , - nothing. It should return an array of items of RoomInfo type, as I understood. Maybe I should declare a list or an array to use it even if it is of common type?

The console log: "RoomInfo[]"

Here’s the code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using System.Collections.Generic;
 
 public class MainMenu2 : MonoBehaviour {
     
     
     void Update () {
         
         if (Input.GetKeyDown (KeyCode.B)) {
             Debug.Log (PhotonNetwork.GetRoomList ());
         }
         
     }
 
     
     public void Connect() {
         Debug.Log("connect()");
         PhotonNetwork.ConnectUsingSettings( "New Unity Project" );
     }
     
     public void OnJoinedLobby() {
         Debug.Log ("OnJoinedLobby");
         PhotonNetwork.JoinRandomRoom();
     }
 
     public void OnPhotonRandomJoinFailed() { //when no room can be entered (all rooms are full or no rooms at all)
         Debug.Log ("OnPhotonRandomJoinFailed");
         PhotonNetwork.CreateRoom( null ); //null = creates a room with a random name
     }
 }
 

(If you are interested, the API is located here, search for “GetRoomList” : http://doc-api.photonengine.com/en/pun/current/class_photon_network.html#aeef2085375accb7d4bc88e60cbe15eb9)

Thank you very much!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Landern · Oct 28, 2015 at 01:07 PM

You probably need to refactor your code, but lets say you use the key 'b' to refresh the room list. Based off the console log you are in fact getting an array of RoomInfo types back, now you need to hold on to that value(s) and use each instance of RoomInfo in the array to pull out the information you want to display for the user to select a preexisting room to join.

Below is an example of storing the array of RoomInfo types in a local private variable and using debug.log to display some information. This is probably something you would want to put in your GUI in a list for selection if any rooms exist.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using System.Collections.Generic;
 
 public class MainMenu2 : MonoBehaviour {
     private RoomInfo[] availableRooms = null;
 
     void Update () {
 
         if (Input.GetKeyDown (KeyCode.B)) {
             availableRooms = PhotonNetwork.GetRoomList();
             if (availableRooms != null && availableRooms.Length > 0){
                 Debug.Log("Number of available rooms: " + availableRooms.Length);  // Length will get you the number of items in the array
                 
                 for (int i = 0; i < availableRooms.Length; i++)
                     Debug.Log("Available Room #" + i+1 + " - Room name: " + availableRooms.name);
             } else {
                 Debug.Log("There are preexisting rooms available");
             }
         }
     }
 
     public void Connect() {
         Debug.Log("connect()");
         PhotonNetwork.ConnectUsingSettings( "New Unity Project" );
     }
 
     public void OnJoinedLobby() {
         Debug.Log ("OnJoinedLobby");
         PhotonNetwork.JoinRandomRoom();
     }
 
      //when no room can be entered (all rooms are full or no rooms at all)
     public void OnPhotonRandomJoinFailed() {
         Debug.Log ("OnPhotonRandomJoinFailed");
         PhotonNetwork.CreateRoom( null ); //null = creates a room with a random name
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Fewpwew130 · Oct 28, 2015 at 09:11 PM

Landern, thank you very much!!!!!!!!!!!

You quickly replied to my question, you understood it, you answered it, you provided a working code and fully commented it. WOW. Thank you. Networking is hard for me and you helped a lot.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

33 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

changing reference types to value types 1 Answer

Remove connection between lists or arrays 3 Answers

List.contain only one variable 1 Answer

I have trouble understanding arrays and enums. When and how? 0 Answers

All GameObjects list to a GameObject? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges