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

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

ojaro
Posts: 10
Joined: 10 Dec 2010, 12:53

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

Postby ojaro » 14 Dec 2010, 10:26

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
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 14 Dec 2010, 12:23

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;
   }
}
ojaro
Posts: 10
Joined: 10 Dec 2010, 12:53

Postby ojaro » 14 Dec 2010, 13:11

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
ojaro
Posts: 10
Joined: 10 Dec 2010, 12:53

Postby ojaro » 14 Dec 2010, 13:33

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?
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 14 Dec 2010, 15:26

i don't see any errors no... odd.

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 2 guests