SmartFox usernames

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

SmartFox usernames

Postby appels » 01 Aug 2010, 02:46

Hi,

I'm trying to get the usernames from a room into an array so i can access them easily in Unity.
This is what i do:

Code: Select all

SmartFoxClient client = NetworkController.GetClient();
Hashtable users = new Hashtable();

using UnityEngine;
using System;
using System.Collections;
using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;
using SmartFoxClientAPI.Util;

public class getUsers : MonoBehaviour {

        SmartFoxClient client = NetworkController.GetClient();
   Hashtable users = new Hashtable();

void Start ()
{
      Room currentActiveRoom = client.GetActiveRoom();
      Hashtable users = currentActiveRoom.GetUserList();
      foreach(User u in users)
               u.GetName();
}


This doesn't work at all.
Is there more info on how to construct this in C#.
All i can find is Actionscript.
Ed.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 01 Aug 2010, 07:38

Do you get any errors?

From what I can spot, you are missing a .Values in your foreach loop.

Need to write (check the API documentation for Room.GetUserList()):

Code: Select all

foreach (User u in users.Values) {
  Debug.Log(u.GetName());
}


If that doesnt work for you, then post some more debug info
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 01 Aug 2010, 09:23

Hi Thomas,

yes, i was messing around with the code and forgot to put that back.
This is my code now :

Code: Select all

using UnityEngine;
using System;
using System.Collections;
using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;
using SmartFoxClientAPI.Util;

public class getUsers : MonoBehaviour {

SmartFoxClient client = NetworkController.GetClient();
Hashtable users = new Hashtable();

void Start () {
      Room currentActiveRoom = client.GetActiveRoom();
      Hashtable users = currentActiveRoom.GetUserList();
      foreach(User u in users.Values)
      Debug.Log(u.GetName());
}


but i get error :


Assets/Game/Scripts/getUsers.cs(24,24): error CS1061: Type `getUsers.User' does not contain a definition for `GetName' and no extension method `GetName' of type `getUsers.User' could be found (are you missing a using directive or an assembly reference?)
Ed.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 01 Aug 2010, 09:43

i can't even get the active room.
this gets called upon join room:
Room currentActiveRoom = client.GetActiveRoom();
Debug.Log(currentActiveRoom);
and i get a null.
Ed.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 01 Aug 2010, 09:46

And you are sure this code is not executed before you actually have a connection, is logged in and joined a room?
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 01 Aug 2010, 10:39

ok, i don't seem to have entered a room but i don't know how to do that. All i can find to do that is smartFox.joinRoom("The Garden") but smartFox isn't known.
Why are the examples with smartfox.* and i'm using client.*
isn't this called on the client connection ?
Do I need to construct something else ?
Ed.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 01 Aug 2010, 11:46

ok, i managed to enter a room.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 01 Aug 2010, 12:46

appels wrote:ok, i don't seem to have entered a room but i don't know how to do that. All i can find to do that is smartFox.joinRoom("The Garden") but smartFox isn't known.
Why are the examples with smartfox.* and i'm using client.*
isn't this called on the client connection ?
Do I need to construct something else ?
Ed.


Its an instance variable of the API - it can be called anything. In all/most examples I simply adopted to call it smartFox.

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 2 guests