Search Unity

Stupid issue, "Goto" level expert

Discussion in 'Scripting' started by Simon75012, Jun 11, 2019.

  1. Simon75012

    Simon75012

    Joined:
    Sep 15, 2016
    Posts:
    79
    Hi,
    I'm having a funny issue, i have to connect to a database using json and one of the mysql row named "goto" !

    My class to import the data is like this

    Code (CSharp):
    1. [Serializable]
    2.     public class User {
    3.         public int id,userId,language,level;
    4.         public string name,email,date;
    5.         ////////public int goto; IMPOSSIBLE
    6.     }
    And then to collect a list of users info :
    Code (CSharp):
    1. WWW www = new WWW(url,form);
    2. yield return www;
    3. if (!string.IsNullOrEmpty(www.error))
    4.      Debug.Log("ERROR " + www.error);
    5. else{
    6.      Debug.Log(www.text);
    7.      users = JsonHelper.getJsonArray<User>(www.text);
    8. }
    Everything is looking great, exept that i can't get the "goto" row as i can't create an int variable named goto...
    Is there a way to create a variable named goto?
    int goto=0; ?

    Thanks.
     
  2. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    What is the error you get when creating the goto field? cause there shouldn't be any error.
    Also you can place it behind the
    public int id,userId,language,level
    like this:
    public int id,userId,language,level,goto;


    sidenote: WWW is deprecated, should replace that at some point.
     
  3. Simon75012

    Simon75012

    Joined:
    Sep 15, 2016
    Posts:
    79
    I tried to place it in many way bubt i always have this error :
    error CS1519: Unexpected symbol `goto' in class, struct, or interface member declaration
     
  4. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Code (CSharp):
    1.  
    2. // You can use keywords as var names if prefixed with @ like this
    3. int @goto = 1;
     
    Simon75012 likes this.
  5. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    ah right, goto is a keyword in C# which makes the execution go to a set label... i.e

    Code (CSharp):
    1. private void Start()
    2. {
    3.    MyLabel:
    4.    var someValue = Mathf.Random(0, 100);
    5.    if(someValue < 50)
    6.       goto MyLabel;
    7. }
    Basically if the value is below 50 it will execute the Mathf.Random again

    Indeed put a @ sign in front of the variable name
     
    Simon75012 likes this.
  6. Simon75012

    Simon75012

    Joined:
    Sep 15, 2016
    Posts:
    79
    Great that worked indeed.
    Thanks for the tips guys
     
  7. Simon75012

    Simon75012

    Joined:
    Sep 15, 2016
    Posts:
    79
    I have the same kind of problem again with special SQL function.
    example : select name,count(id) from ****** where ***** group by name

    Result : [{"name":"Name 1","count(id)":"1"},{"name":"Name 2","count(id)":"3"},{"name":"Name 3","count(id)":"100"}]

    I can't find a way to parse that string and get the count...
     
  8. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Code (CSharp):
    1. int count = int.Parse("42");