Search Unity

Unexpected symbol `(', expecting `)', `,', `;', `[', or `='

Discussion in 'Scripting' started by Shadowing, Feb 1, 2015.

  1. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    Getting hit with the error

    The body of `login_manager.Login()' cannot be an iterator block because `void' is not an iterator interface type

    Wonder if anyone has any idea

    Code (csharp):
    1.  
    2.  
    3. public class login_manager : MonoBehaviour {
    4.  
    5.     public WWWForm form = new WWWForm();
    6.     public string headers = form.headers;
    7.     public byte[] rawData = form.data;
    8.     public string url = "www.url.dev";
    9.     public WWW www = new WWW(url, rawData, headers);
    10.  
    11. public void Login(){
    12.  
    13.  
    14.        form.AddField("name", "value");
    15.        headers["Authorization"] = "Basic " +   System.Convert.ToBase64String                                                                      (System.Text.Encoding.ASCII.GetBytes("username:password"));
    16. yield return www;
    17.  
    18.  
    19.  
    20. }
    21. }
    22.  
    23.  
     
    Last edited: Feb 1, 2015
  2. Deleted User

    Deleted User

    Guest

    uhh... Im not trying to offend you but this looks like a typically copy/paste / I have no clue what Im doing error. Do your self a favor, take a deep breath and lern the basics of scripting//programming befor attempting to make videogames.

    to get to your code: line 3 - 7 are outside any method body and the rest is a method inside another method, wich both is not valid

    EDIT:
    well know this looks better atleast... to yield on a method you need to retun an IEnumerator and call the method with StartCroutine( Login() )
     
    Last edited by a moderator: Feb 1, 2015
    Jessy likes this.
  3. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    Oh ya you must of replied when I was in the middle of editing it lol.
    Actually I've decided to just give up on C# and just use JavaScript. The language is just to strict for me;
    Learning Unity is hard enough as it is then to use a new language I've never wrote in before.

    I have a heavy 3 years experience in javascript and php. After reading some C# docs online I just realize how much different it is lol.

    I appreciate the reply element_wsc
    Cheers!
     
    Last edited: Feb 1, 2015
  4. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    It really isn't. UnityScript (js files) isn't true javascript.
    The differences between UnityScript and the C# you'd be doing is very slight.
    http://unity3d.com/learn/tutorials/modules/beginner/scripting/c-sharp-vs-javascript-syntax
    Differences explained in less than 2 minutes
    Theres also a few things that US simply can't do, but c# can
     
    Jessy likes this.
  5. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    that's weird that tutorial says that # pragma strict forces you to declare a type when declaring stuff with javasscript but it seems it doesn't.

    Idk seems to be way more differences then what this video shows. What I've been noticing so far the last few days.
    like declaring the function return type, void, and some other weird names. So I guess thats one of the things I was stuck on and now I understand the error when it was saying the return type was wrong on the function lol.

    I think the function was returning a string and I was using void. So I guess I should of used string myfunctionname() for C#

    Actually all the javascript example code don't even declare type either. Whats the deal with that?
     
    Last edited: Feb 1, 2015
  6. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    Also I was thinking if I do use javascript then I can maybe use something like php.js http://phpjs.org/ so I can use a php functions. If that will even work that is
     
    Last edited: Feb 1, 2015
  7. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    He types the variable, function, and the function parameter, the variable 'ret' on line 7 is typed by inference (it's immediately assigned a value that can only be an int)

    pragma strict diables dynamic typing (you can have a variable store an int , then store a string in it - gives problems if you try to string.Split the int)

    void just means a method doesn't return a value back to where it was called from

    I've no idea bout php, think iv'e seen some topics here about it, but i ignore them