-1

I have the following code:

socket.On ("chat", (data) => {
                string str = data.ToString ();

                ChatData chat = JsonConvert.DeserializeObject<ChatData> (str);
                string strChatLog = "user#" + chat.id + ": " + chat.msg;

                int pos = userArr.IndexOf (chat.id);
                if (pos > -1) {
                    var InsObj = Instantiate (player, StringToVector3 (chat.msg), Quaternion.identity);
                    InsObj.name = chat.id;
                    userArr [userArr.Length + 1] = chat.id;
                }

                // Access to Unity UI is not allowed in a background thread, so let's put into a shared variable
                lock (chatLog) {
                    chatLog.Add (strChatLog);
                }
            });

When I try to run it I get this error:

Assets/SocketIO/SocketIOScript.cs(59,23): error CS1593: Delegate `System.Action' does not take `1' arguments

However when I remove this part :

int pos = userArr.IndexOf (chat.id);
                if (pos > -1) {
                    var InsObj = Instantiate (player, StringToVector3 (chat.msg), Quaternion.identity);
                    InsObj.name = chat.id;
                    userArr [userArr.Length + 1] = chat.id;
                }

It works just fine.

I am wondering why this is happening, I have been trying to figure it out for quite a while. I found this post about it, but that did not help me much, because I don't think that I can specify data.

EDIT:

StringToVector3 contains the following code (However even if I get rid of StringToVector3 I still get the error):

public static Vector3 StringToVector3 (string sVector)
    {
        // Remove the parentheses
        if (sVector.StartsWith ("(") && sVector.EndsWith (")")) {
            sVector = sVector.Substring (1, sVector.Length - 2);
        }

        // split the items
        string[] sArray = sVector.Split (',');

        // store as a Vector3
        Vector3 result = new Vector3 (
                             float.Parse (sArray [0]),
                             float.Parse (sArray [1]),
                             float.Parse (sArray [2]));

        return result;
    }
zoecarver
  • 5,523
  • 2
  • 26
  • 56
  • What is `StringToVector3 `? Looks like you're calling a function with a `void` return type, or an `Action` – Rob Jul 18 '17 at 02:53
  • I have added `StringToVector3`, However I still get the same error if I exclude it. Thank you for your help! – zoecarver Jul 18 '17 at 02:57
  • `StringToVector3` is already returning a `Vector3` - do you really need to pass it to a constructor? Can you just instead write: `Instantiate (player, StringToVector3 (chat.msg), Quaternion.identity);` – Rob Jul 18 '17 at 03:00
  • Thank you for noticing that. I made an edit, however I still get the same error using the code you provided, I even get that error if I remove the `StringToVectory3` completely. – zoecarver Jul 18 '17 at 03:01

1 Answers1

0

The issue was that I needed to use System.Array.IndexOf Instead of userArr.IndexOf

zoecarver
  • 5,523
  • 2
  • 26
  • 56