i am using some codes from the simple chat demo but it compiles with errors.
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Entities;
using Sfs2X.Requests;
using Sfs2X.Logging;
private SmartFox smartFox;
void Start ()
{
bool debug = false;
smartFox = new SmartFox(debug);
}
with just those codes i got
error CS1729: The type SmartFox' does not contain a constructor that takes 1’ arguments
looking up the smartfox C# docs, clearly it has a constructor with 1 argument. i did put in the smartfox2.dll file in my plugins folder.
another question:
this login UI is in c# but i would like it access a singleton that is written in JavaScript. i have read the documentation concerning the order of compilation but i have concerns in changing the order of compilation of the project as i am taking over the codes from someone else.
at current, the project has JS scripts 1 step above the C# scripts. since it uses the water manager from the PRO assets.
i guess this leads me to ask do i need to convert the preexisting code to C# or is there another way to get this to work with out changing the structure of the compilation?
Where is your class name ? Or did you post just part of the script ?
I don’t see anything else wrong.
I would convert the Unityscript files to C# but i’m a C# guy.
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Entities;
using Sfs2X.Requests;
using Sfs2X.Logging;
public class MainMenuGUI : MonoBehaviour
{
public int menuWidth = 100;
public int menuHeight = 100;
public string menuTitle = "Title";
public GUISkin menuSkin;
private string loginErrorMessage = "";
private string username;
private string userpwd;
private string zone = "Heritage";
private SmartFox smartFox;
private bool isConnected;
public GameObject sManage;
// Use this for initialization
void Start ()
{
bool debug = false;
if (SmartFoxConnection.IsInitialized)
{
smartFox = SmartFoxConnection.Connection;
}
else
{
smartFox = new SmartFox(debug);
}
smartFox.AddLogListener(LogLevel.INFO, OnDebugMessage);
}
// Update is called once per frame
void FixedUpdate ()
{
smartFox.ProcessEvents();
}
private void AddEventListeners() {
smartFox.RemoveAllEventListeners();
smartFox.AddEventListener(SFSEvent.CONNECTION, OnConnection);
smartFox.AddEventListener(SFSEvent.LOGIN, OnLogin);
}
public void OnConnection(BaseEvent evt) {
bool success = (bool)evt.Params["success"];
if (success) {
SmartFoxConnection.Connection = smartFox;
Debug.Log("Connected...");
isConnected=true;
smartFox.Send(new LoginRequest(username, userpwd, zone));
}
}
public void OnLogin(BaseEvent evt) {
try {
if (evt.Params.ContainsKey("success") !(bool)evt.Params["success"]) {
loginErrorMessage = (string)evt.Params["errorMessage"];
Debug.Log("Login error: "+loginErrorMessage);
}
else {
Debug.Log("Logged in successfully");
// Startup up UDP
smartFox.InitUDP(serverName, serverPort);
}
}
catch (Exception ex) {
Debug.Log("Exception handling login request: "+ex.Message+" "+ex.StackTrace);
}
}
public void OnGUI()
{
//GUI.Window(0, Rect((Screen.width-menuWidth)/2, (Screen.height-menuHeight)/2, menuWidth, menuHeight), drawMenu, menuTitle, menuSkin.window);
GUILayout.BeginVertical();
username = GUI.TextField(new Rect(100, 90, 200, 20), username, 20);
userpwd = GUI.PasswordField(new Rect(100, 90, 200, 20), userpwd, "*"[0],20);
if (GUILayout.Button("Start Game", menuSkin.button) || (Event.current.type == EventType.keyDown
Event.current.character == '\n'))
{
AddEventListeners();
smartFox.Connect("localhost", 9933);
smartFoxSend(new LoginRequest(username, userpwd, "Heritage"));
//this the javascript singleton i'm trying to call
//sceneManager.loadLevel("islandStream");
}
GUILayout.EndVertical();
}
}
that is the code. basically all the smartFox variables can’t be seen by the compiler.
as for converting the pre-existing code, i have a feeling i had to do that… i’m need to bring it up with the higher ups unless i can find a workaround.
smartFox.Send(new LoginRequest(username, userpwd, “Heritage”));
is used 2x, remove the one in the gui, you need to call that in the OnConnected callback.
and it’s not smartFoxSend but smartFox.Send
If your SFS DLL is in the plugins folder, this shouldn’t give any errors.
thanks appels for the quick post. i think i found out what was causing the error CS1729: The type SmartFox' does not contain a constructor that takes 1’ arguments.
the project had the SmartFoxClient.dll in the plugins folder as well. after i removed it, the compiler did not give anymore of those errors.