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.

Regards,

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.events;
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.initialize(apiKey,secretKey);
        WarpClient.GetInstance().AddConnectionRequestListener(listen);
        //WarpClient.GetInstance().AddChatRequestListener(listen);
        WarpClient.GetInstance().AddUpdateRequestListener(listen);
        WarpClient.GetInstance().AddLobbyRequestListener(listen);
        WarpClient.GetInstance().AddNotificationListener(listen);
        WarpClient.GetInstance().AddRoomRequestListener(listen);
        WarpClient.GetInstance().AddZoneRequestListener(listen);
        


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

        WarpClient.GetInstance().SubscribeRoom(roomid);
        WarpClient.GetInstance().JoinRoom(roomid);


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

        
      


        // listen.onGetLiveRoomInfoDone(roomData);



        //EditorApplication.playmodeStateChanged += OnEditorStateChanged;
        addPlayer();


        

    }
   
   


    public void addPlayer()
    {



        conectedUsers = new AllUsersEvent(getUsersResult, users);
        listen.onGetOnlineUsersDone(conectedUsers);



        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+"\"}";
           
            listen.sendMsg(json);
           
            timer = interval;
        }
       
        if (Input.GetKeyDown(KeyCode.Escape)) {
            Application.Quit();
        }

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



        WarpClient.GetInstance().Update();
        obj.transform.position = Vector3.Lerp(obj.transform.position, newPos, Time.deltaTime);
    }



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

    }
   

    void OnApplicationQuit()
    {
        WarpClient.GetInstance().Disconnect();
    }
   
}
 [/quote]

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

[img] https://drive.google.com/file/d/0B5VocdPbQPqVZmJlYnRjRk9sR2c/view?usp=sharing [/img]

https://drive.google.com/file/d/0B5VocdPbQPqVZmJlYnRjRk9sR2c/view?usp=sharing
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(https://github.com/RajeevRShephertz/AppWarpUnitySample/tree/master/AppWarpUnitySample/Assets/Scripts).

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 support@shephertz.com
...