Trouble getonlineusers sintaxis

0 votes
I am still having some trouble with getting the number of users connected to a room. I am using app42 cloud and the code is like this ( unity3d in c#) Listener listen; Addlisteners........ Public string[] users; Public byte result; Public AllUsersEvent eventOnlineUsr; Appwarp.GetInstance().getOnlineUsers () ; Listen.onGetOnlineUsersDone( eventOnlineUsr); The code does not produce errors but the values of the srring of the users and the value of the function onGetOnlineUsersDone() (result) are not updated. I am able to understand the observer patterns used for your app, but I do not know how to do it properly in sintaxis. I will apreciate some help in this topic or some examples because I want to retrieve the number of users conected always in each iteration. Yours faithfully.
asked Dec 16, 2015 in AppWarp by michael.soler.beatty (10 points)

1 Answer

0 votes

hello Michael,

Could you please elaborate your query more like as you said code does not produce any error but the values of the string of the users are not updated in case of onGetOnlineUsersDone? Because for my understanding onGetOnlineUserDone is not giving any error or response am i correct? If yes, then if it is possible please do share your complete sample code with us.  It will help us to provide better support to you.


Himanshu Sharma

answered Dec 17, 2015 by hs00105 (2,005 points)
Well, this is the code:

[quote]  using UnityEngine;
using System.Collections;
using System.Collections.Generic;

using com.shephertz.app42.gaming.multiplayer.client;
using com.shephertz.app42.gaming.multiplayer.client.listener;
using com.shephertz.app42.gaming.multiplayer.client.command;
using com.shephertz.app42.gaming.multiplayer.client.message;
using com.shephertz.app42.gaming.multiplayer.client.transformer;

//using UnityEditor;

using AssemblyCSharp;

public class appwarp : MonoBehaviour {

    //please update with values you get after signing up
    public static string apiKey = "..";
    public static string secretKey = "...";
    public static string roomid = "...";

    public static string username;
    Listener listen = new Listener();

    public AllUsersEvent conectedUsers;
    public string[] users;
    public byte getUsersResult;

    public static Vector3 newPos = new Vector3(0,0,0);
    public bool debugON;

    public Vector3 position01, position02;

    public float interval = 0.1f;
    float timer = 0;
    public static GameObject obj;

    void Start () {;


        //WarpClient.GetInstance ().AddTurnBasedRoomRequestListener (listen);


        // join with a unique name (current time stamp)
        username = System.DateTime.UtcNow.Ticks.ToString();


        // listen.onGetLiveRoomInfoDone(roomData);

        //EditorApplication.playmodeStateChanged += OnEditorStateChanged;



    public void addPlayer()

        conectedUsers = new AllUsersEvent(getUsersResult, users);

        obj = GameObject.CreatePrimitive(PrimitiveType.Capsule);
        obj.transform.position = new Vector3(732f,1.5f,500f);

    public static void movePlayer(float x, float y, float z)
        newPos = new Vector3(x,y,z);

    void Update () {
        timer -= Time.deltaTime;

        if (timer < 0)


            string json = "{\"x\":\""+transform.position.x+"\",\"y\":\""+transform.position.y+"\",\"z\":\""+transform.position.z+"\"}";
            timer = interval;
        if (Input.GetKeyDown(KeyCode.Escape)) {

        Debug.Log("conected users=  " + conectedUsers.getResult() + "  string users = " + conectedUsers.getUserNames().Length);

        obj.transform.position = Vector3.Lerp(obj.transform.position, newPos, Time.deltaTime);

    void OnGUI()
        if (debugON == true)
            GUI.contentColor =;
            GUI.Label(new Rect(10, 10, 500, 200), listen.getDebug());


    void OnApplicationQuit()

And, as I have made the variables public, they should be updated during the iteration (I madethis as a sort of debug).

[img] [/img]
Hello Michael,

After going through the above code snippets, i see that you are calling the callback onGetOnlineUsersDone which is not required.
You just need to call getOnlineUsers API and if listeners are set properly and callback is defined then it will be called by the AppWarp SDK in response of the api call.

I also saw that you are calling joinRoom API before connect which will will give you bad_request error always as the user is not connected to the AppWarp Server. So before calling any api, you must be connected to the server.

Please have a look at out sample(

The sample has button based api call demo, you just need to run the sample and start calling the API by tapping the button. Before calling any other api you must call connect.

Let me know if you face any problem.
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