Page 1 of 1

SmartFox.IsInitialized() doesn't exist in the current contex

Posted: 14 Dec 2010, 10:26
by ojaro
Hi all,

I see folks using line SmartFox.IsInitialized() in order to detect if we already have opened a connection to the server. I keep getting the following error when using it:

The name `SmartFox' does not exist in the current context

Could someone tell me how to resolve? Looking through people's examples I seem to be including the same namespaces that everyone else:

using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;
using SmartFoxClientAPI.Util;

I must be missing something really obvious here...?

Regards,

Olli

Posted: 14 Dec 2010, 12:23
by appels
there is a static class 'SmartFox' where they refer to that holds the connection info and where you can check if the connection has been initialized.

Code: Select all

using UnityEngine;
using SmartFoxClientAPI;

// Statics for holding the connection to the SFS server end
// Can then be queried from the entire game to get the connection

public static class SmartFox {
   private static SmartFoxClient smartFox;
   public static SmartFoxClient Connection {
      get { return smartFox; }
      set { smartFox = value; }
   }

   public static bool IsInitialized() {
      if ( smartFox != null ) {
         return true;
      }
      return false;
   }
}

Posted: 14 Dec 2010, 13:11
by ojaro
Aah ok. That is not the cause for my issue then :( I thought that maybe I am leaving the connection open or something...

What it is, is that I have some real simple test code. This morning it was connecting fine, but now it just hangs... I know that the server is ok, since can connect to it with the SFS island demo.

Well I will paste my test code below in case I have done something really stupid and obvious here. But anyone have any ideas why this might be happening? I had similar problems yesterday when testing with saving user variables. Initially they saved and got broadcasted fine, but then the server just started ignoring my requests.

Anyway, the test code is below(with this the HandleConnection will get nevel called):

Code: Select all

using UnityEngine;
using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;
using SmartFoxClientAPI.Util;
using System.Collections;

public class SFSConnectionTester : MonoBehaviour {
   
   private string serverName = "192.168.227.128";
   private int serverPort = 9339;
   private string zoneName = "simpleChat";
   private string modName = "modName";
   private string modPass = "modPass";
   
   private static SmartFoxClient smartFox = null;
   private string statusMessage;
   
   // Use this for initialization
   void Start () {
      statusMessage = "Start Test";
      smartFox = new SmartFoxClient(true);
      SFSEvent.onConnection += HandleConnection;
      SFSEvent.onDebugMessage += OnDebugMessage;
      statusMessage = "Connecting to server:" + serverName + ":" + serverPort;
   }
   
   void HandleConnection(bool success, string error) {
      if (success) {
         statusMessage = "Connection succesful!";
         smartFox.Login(zoneName, modName, modPass);
      } else {
         statusMessage = "Can't connect! Error: " + error;
      }
   }   
      
   void OnGUI(){
      GUI.Label(new Rect(10, 10, 500, 100), "Status: " + statusMessage);
   }
   
   public void OnDebugMessage(string message) {
       Debug.Log("[SFS DEBUG] " + message);
   }
}


Regards,

Olli

Posted: 14 Dec 2010, 13:33
by ojaro
Hmmm.... Created a completely new project and pasted in the test code. And now suddenly it is connecting to the server again! Anyone able to point out the logic in this?

Posted: 14 Dec 2010, 15:26
by appels
i don't see any errors no... odd.