[SOLVED] Not getting any Debug.Log or print messages after connection

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

[SOLVED] Not getting any Debug.Log or print messages after connection

Postby Ninjaoninja2 » 24 Nov 2017, 22:25

Hi all,
For the past couple of weeks I've found something odd happening within Unity. My player can connect and login - I know because the SFS2X logs are showing him/her logged in. But for some reason after the login my join room request is not sent like it was doing before and my Debug.Log and print commands are not working when something happens in Unity just in this specific project, and it's only not working when needing a response back from SFS, so let's say I have a random button in another scene and on that button click I call a Debug.Log("Hi"); that button will print Hi in the console. But in regards to SFS nothing comes back and I can't even switch scenes now. Also, other SFS Example projects are able to use Debug.Log.
Here's my only script so far:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Requests;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
public class Connect : MonoBehaviour {
   public Button loginbtn;
   public Text debugText;
   SmartFox sfs = new SmartFox();
   void Start() {
      sfs.Connect ("**.**.**.***", 9933);
      sfs.AddEventListener (SFSEvent.CONNECTION, onConnect);
      sfs.AddEventListener (SFSEvent.CONNECTION_LOST, onConnectFail);
      sfs.AddEventListener (SFSEvent.LOGIN, onLogin);
      sfs.AddEventListener (SFSEvent.CRYPTO_INIT, onCryptoInit);
      sfs.AddEventListener (SFSEvent.ROOM_JOIN, onRoomJoin);
   }
   void Update() {

   }
   void onConnect (BaseEvent evt) {
      print ("Connected");
      debugText.text = "Loaded";
   }
   void onConnectFail(BaseEvent evt) {
      Debug.Log("It didn't work.");
   }

   void onCryptoInit(BaseEvent evt) {
      Debug.Log ("Succesful Encryption");
   }
   void onLogin(BaseEvent evt) {
      Debug.Log ("YAY!");
      sfs.Send (new Sfs2X.Requests.JoinRoomRequest ("Village"));
   }

   public InputField username;
   public string Username;
   //fries is the Username game object.
   public void getInput(string Username) {
      Debug.Log ("Username entered :" + Username);
      GetComponent<InputField> ();
      Username = username.text;
      //sendLogin ();
   }
   public InputField password;
   public string Password;

   //straw is the Password game object.
   public void getInputP(string Password) {
      GetComponent<InputField> ();
      Debug.Log ("Password entered :" + password);
      Password = password.text;
      //sendLogin ();
   }
   public void sendLogin() {
      GetComponent<InputField> ();
      sfs.Send (new Sfs2X.Requests.LoginRequest (username.text, password.text, "SP"));
   }
   public void onRoomJoin(BaseEvent evt) {
      SceneManager.LoadScene ("Game");
   }
}
Last edited by Ninjaoninja2 on 28 Nov 2017, 03:18, edited 1 time in total.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Not getting any Debug.Log or print messages after connection

Postby Bax » 27 Nov 2017, 07:59

Very hard to guess what might be going on here.
What I noticed is that you call the Connect method before adding the SFSEvent listeners.
Can you reverse that? Any difference?
Paolo Bax
The SmartFoxServer Team
Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Re: Not getting any Debug.Log or print messages after connection

Postby Ninjaoninja2 » 27 Nov 2017, 23:21

Bax wrote:Very hard to guess what might be going on here.
What I noticed is that you call the Connect method before adding the SFSEvent listeners.
Can you reverse that? Any difference?

Didn't seem to do it either, It's odd because I have the connect script attached to an empty game object.
Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Re: Not getting any Debug.Log or print messages after connection

Postby Ninjaoninja2 » 28 Nov 2017, 02:04

Bax wrote:Very hard to guess what might be going on here.
What I noticed is that you call the Connect method before adding the SFSEvent listeners.
Can you reverse that? Any difference?

So, I went ahead and redid a script with just a basic layout. It goes like this:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Requests;

public class Connect : MonoBehaviour
{
   public Text debugText;
   public string message;
    SmartFox sfs = new SmartFox();
    // Use this for initialization
    void Start()
    {
      trace ("started");
      //sfs.AddEventListener(SFSEvent.CONNECTION, onConnect);
      //sfs.AddEventListener (SFSEvent.CONNECTION_LOST, onConnectFail);
      message = "";
      sfs.AddLogListener (Sfs2X.Logging.LogLevel.DEBUG, onLogMessage);
        sfs.Connect("127.0.0.1", 9933);
    }
   private void trace(string msg) {
      debugText.text += (debugText.text != "" ? "\n" : "") + msg;
      Canvas.ForceUpdateCanvases ();

   }

   public void onLogMessage(BaseEvent evt) {
      string message = (string)evt.Params ["message"];
      ShowLogMessage ("INFO", message);
         
   }

   private void ShowLogMessage(string level, string message) {
      message = "[SFS> " + level + "]" + message;
      Debug.Log (message);
      trace (message);
   }
}

If I comment out the onConnect and onConnectFail event listeners and take out the onConnect and onConnectFail functions, debugText automatically changes to "started" from the trace function. So, it seems that the event listeners are not getting called. Because I can see connections via the admin tool's logs.

UPDATE: Even ShowLogMessage works just not on the listeners, any ideas why Unity might not be calling these listeners?
Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Re: [SOLVED] Not getting any Debug.Log or print messages after connection

Postby Ninjaoninja2 » 28 Nov 2017, 03:18

All good now, forgot to add this line here:
void Update() {
sfs.ProcessEvents ();
}
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: [SOLVED] Not getting any Debug.Log or print messages after connection

Postby Bax » 28 Nov 2017, 08:57

Ouch, didn't notice it in your first code snippet. Sorry.
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 30 guests