Page 1 of 1

SmartFox usernames

Posted: 01 Aug 2010, 02:46
by appels
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.

Posted: 01 Aug 2010, 07:38
by ThomasLund
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

Posted: 01 Aug 2010, 09:23
by appels
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.

Posted: 01 Aug 2010, 09:43
by appels
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.

Posted: 01 Aug 2010, 09:46
by ThomasLund
And you are sure this code is not executed before you actually have a connection, is logged in and joined a room?

Posted: 01 Aug 2010, 10:39
by appels
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.

Posted: 01 Aug 2010, 11:46
by appels
ok, i managed to enter a room.

Posted: 01 Aug 2010, 12:46
by ThomasLund
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.