Search Unity

Help my script plz!

Discussion in 'Multiplayer' started by Lejoparden, Aug 20, 2014.

  1. Lejoparden

    Lejoparden

    Joined:
    Aug 8, 2014
    Posts:
    6
    using UnityEngine;
    using System.Collections;
    using Sfs2X;
    using Sfs2X.Core;
    using Sfs2X.Requests;
    using Sfs2X.Entities;

    public class NetworkingClient : MonoBehaviour {

    private string host = "localhost"; //The ip the client tries to connect to
    private int port = 9933; //The port the client tries to connect to the server on

    public SmartFox _client;

    // Use this for initialization
    void Start () {
    _client = new SmartFox ();
    _client.ThreadSafeMode = true;
    _client.AddEventListener(SFSEvent.CONNECTION, OnConnection;
    Connect ();
    }

    // Update is called once per frame
    void FixedUpdate () {
    _client.ProcessEvents();
    }

    public void Connect() {
    _client.Connect (host, port:);
    }

    void OnConnection(BaseEvent _event) {
    if((bool)_event.Params["success"]) {
    //Successful
    Debug.Log ("Successfully connected to server");
    } else {
    //Failed
    Debug.Log ("Failed connecting to server");
    }
    }

    Whats wrong with my script please help me guys! :(
     
  2. Cha0os

    Cha0os

    Joined:
    Feb 22, 2014
    Posts:
    17
    Code (CSharp):
    1. _client.AddEventListener(SFSEvent.CONNECTION, OnConnection;
    You are missing a bracket at the end of that line. Maybe that's your problem...
     
  3. Lejoparden

    Lejoparden

    Joined:
    Aug 8, 2014
    Posts:
    6
    can you plz put it in my sript and send me the whole script.. I feel really retarded now :(
     
  4. Cha0os

    Cha0os

    Joined:
    Feb 22, 2014
    Posts:
    17
    It's in the Start()-function:

    Code (CSharp):
    1. // Use this for initialization
    2. void Start () {
    3.   _client = new SmartFox ();
    4.   _client.ThreadSafeMode = true;
    5.   _client.AddEventListener(SFSEvent.CONNECTION, OnConnection);  // <--- This bracket was missing
    6.   Connect ();
    7. }
     
  5. Lejoparden

    Lejoparden

    Joined:
    Aug 8, 2014
    Posts:
    6
    I am still getting this error

    Assets/_Scripts/Networking/NetworkingClient.cs(41,1): error CS8025: Parsing error
     
  6. Cha0os

    Cha0os

    Joined:
    Feb 22, 2014
    Posts:
    17
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Sfs2X;
    4. using Sfs2X.Core;
    5. using Sfs2X.Requests;
    6. using Sfs2X.Entities;
    7.  
    8. public class NetworkingClient : MonoBehaviour {
    9.  
    10.     private string host = "localhost"; //The ip the client tries to connect to
    11.     private int port = 9933; //The port the client tries to connect to the server on
    12.  
    13.     public SmartFox _client;
    14.  
    15.     // Use this for initialization
    16.     void Start () {
    17.         _client = new SmartFox ();
    18.         _client.ThreadSafeMode = true;
    19.         _client.AddEventListener(SFSEvent.CONNECTION, OnConnection);
    20.         Connect ();
    21.     }
    22.  
    23.     // Update is called once per frame
    24.     void FixedUpdate () {
    25.         _client.ProcessEvents();
    26.     }
    27.  
    28.     public void Connect() {
    29.       _client.Connect (host, port:);
    30.     }
    31.  
    32.     void OnConnection(BaseEvent _event) {
    33.         if((bool)_event.Params["success"]) {
    34.           //Successful
    35.           Debug.Log ("Successfully connected to server");
    36.         } else {
    37.           //Failed
    38.           Debug.Log ("Failed connecting to server");
    39.         }
    40.     }
    41. }
    You were missing a curly bracket at the end of the script.

    In order to identify these problems quickly you should try to keep your code well formatted.