OnRoomJoin Event not firing

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

m0rr0ws0n
Posts: 11
Joined: 22 Sep 2017, 12:11

OnRoomJoin Event not firing

Postby m0rr0ws0n » 23 Sep 2017, 10:01

I have a problem when I send a room join request it looks like I'm not getting a room join event back. The sfs Connection is ok and the server contains the room. It's just that the code inside OnRoomJoin() is not executing...any help? :o

Code here:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Sfs2X;
using Sfs2X.Logging;
using Sfs2X.Util;
using Sfs2X.Core;
using Sfs2X.Entities;
using Sfs2X.Entities.Data;
using Sfs2X.Requests;
using Sfs2X.Requests.MMO;
using UI.Dialogs;
using UnityEngine.SceneManagement;
using UMACharacterSystem;

public class SFSWorld : MonoBehaviour {

    public UI.Dialogs.uDialog myDialog;
    public DynamicCharacterAvatar Avatar;

    private SmartFox sfs;

   // Use this for initialization
   void Start () {

        if (SFSInstance.IsInitialized)
        {
           
            sfs = SFSInstance.Connection;
        }
        else
        {
            myDialog.SetContentText("No Smartfox connection.");
            myDialog.Show();
        }

        sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnRoomJoinError);

        string roomName = "World";

        if (sfs.RoomManager.ContainsRoom(roomName))
        {
            sfs.Send(new JoinRoomRequest(roomName));
        }
    }

    private void OnRoomJoin(BaseEvent evt)
    {
        Debug.Log("In World Scene the avatar is: " + SessionInfo.Avatar);
        Avatar.LoadFromRecipeString(SessionInfo.Avatar);
    }

    private void OnRoomJoinError(BaseEvent evt)
    {
        reset();
        Debug.Log("Room join failed: " + (string)evt.Params["errorMessage"]);

        myDialog.SetContentText("Room join failed: " + (string)evt.Params["errorMessage"]);
        myDialog.Show();
    }

    private void reset()
    {
        sfs.RemoveAllEventListeners();
    }

    void OnDialogClose(uDialog arg0)
    {
        SceneManager.LoadSceneAsync("login");
    }
}
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: OnRoomJoin Event not firing

Postby Lapo » 25 Sep 2017, 09:48

Hi,
Aren't there any join errors?
Did you check the logs for possible server side errors?

If none of the above maybe it's an issue with scenes... though I should have more context to understand what might be going on.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
edwinharly
Posts: 4
Joined: 23 Oct 2017, 01:46

Re: OnRoomJoin Event not firing

Postby edwinharly » 31 Jan 2018, 03:49

You forgot sfs.processEvents(); on void Update() { }
edwinharly
Posts: 4
Joined: 23 Oct 2017, 01:46

Re: OnRoomJoin Event not firing

Postby edwinharly » 31 Jan 2018, 03:53

Add these lines

Code: Select all

void Update() {
   if (sfs != null)
      sfs.ProcessEvents();
}


m0rr0ws0n wrote:I have a problem when I send a room join request it looks like I'm not getting a room join event back. The sfs Connection is ok and the server contains the room. It's just that the code inside OnRoomJoin() is not executing...any help? :o

Code here:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Sfs2X;
using Sfs2X.Logging;
using Sfs2X.Util;
using Sfs2X.Core;
using Sfs2X.Entities;
using Sfs2X.Entities.Data;
using Sfs2X.Requests;
using Sfs2X.Requests.MMO;
using UI.Dialogs;
using UnityEngine.SceneManagement;
using UMACharacterSystem;

public class SFSWorld : MonoBehaviour {

    public UI.Dialogs.uDialog myDialog;
    public DynamicCharacterAvatar Avatar;

    private SmartFox sfs;

   // Use this for initialization
   void Start () {

        if (SFSInstance.IsInitialized)
        {
           
            sfs = SFSInstance.Connection;
        }
        else
        {
            myDialog.SetContentText("No Smartfox connection.");
            myDialog.Show();
        }

        sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);
        sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnRoomJoinError);

        string roomName = "World";

        if (sfs.RoomManager.ContainsRoom(roomName))
        {
            sfs.Send(new JoinRoomRequest(roomName));
        }
    }

    private void OnRoomJoin(BaseEvent evt)
    {
        Debug.Log("In World Scene the avatar is: " + SessionInfo.Avatar);
        Avatar.LoadFromRecipeString(SessionInfo.Avatar);
    }

    private void OnRoomJoinError(BaseEvent evt)
    {
        reset();
        Debug.Log("Room join failed: " + (string)evt.Params["errorMessage"]);

        myDialog.SetContentText("Room join failed: " + (string)evt.Params["errorMessage"]);
        myDialog.Show();
    }

    private void reset()
    {
        sfs.RemoveAllEventListeners();
    }

    void OnDialogClose(uDialog arg0)
    {
        SceneManager.LoadSceneAsync("login");
    }
}

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 69 guests