Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Nov 22, 2015 at 06:58 AM by vespa39 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by vespa39 · Oct 31, 2015 at 05:29 AM · c#error message

64,24): warning CS0219: The variable `nextTetromino' is assigned but its value is never used, (131,163): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected

here is the script i am doing for a class, its two parts, also whenever i go to said errors to find out what is going on and even go back to video from class everything on my professor end looks the same as mine so i am not sure what i did wrong -

this is the game script

using UnityEngine; using System.Collections;

public class Game : MonoBehaviour {

 public static int gridWidth = 10;
 public static int gridHeight = 20;

 public static Transform[,] grid = new Transform[gridWidth, gridHeight];

 // Use this for initialization
 void Start () {

     SpawnNextTetromino ();
 
 }
 
 // Update is called once per frame
 void Update () {

 }

 public void updateGrid (Tetromino tetromino) {

     for (int y = 0; y <gridHeight; ++y) {

         for (int x = 0; x <gridWidth; ++x) {

             if (grid [x, y] != null) {

                 if (grid [x, y].parent == tetromino.transform) {

                     grid [x, y] = null;
                 }
             }
         }
     }

     foreach (Transform mino in tetromino.transform) {

         Vector2 pos = Round (mino.position);

         if (pos.y < gridHeight) {

             grid [(int)pos.x, (int)pos.y] = mino;
         }
     }
 }

 public Transform GetTransformAtGetPosition (Vector2 pos) {

     if (pos.y > gridHeight - 1) {

         return null;

     } else {

         return grid [(int)pos.x, (int)pos.y];
     }
 }

 public void SpawnNextTetromino () {

     GameObject nextTetromino = (GameObject)Instantiate(Resources.Load(GetRandomTetromino(), typeof(GameObject)), new Vector2 (5.0f, 20.0f), Quaternion.identity);
 }

 public bool CheckIsInsideGrid (Vector2 pos) {

     return ((int)pos.x >= 0 && (int)pos.x < gridWidth && (int)pos.y >= 0);
 }

     public Vector2 Round (Vector2 pos) {

     return new Vector2 (Mathf.Round(pos.x), Mathf.Round(pos.y));
 }

 string GetRandomTetromino () {

     int RandomTetromino = Random.Range (1, 8);

     string RandomTetrominoName = "Prefabs/Tetromino_T";

     switch (RandomTetromino) {

     case 1:
         RandomTetrominoName = "Prefabs/Tetromino_T";
         break;

     case 2:
         RandomTetrominoName = "Prefabs/Tetromino_Long";
         break;

     case 3:
         RandomTetrominoName = "Prefabs/Tetromino_Square";
         break;

     case 4:
         RandomTetrominoName = "Prefabs/Tetromino_J";
         break;

     case 5:
         RandomTetrominoName = "Prefabs/Tetromino_L";
         break;

     case 6:
         RandomTetrominoName = "Prefabs/Tetromino_S";
         break;

     case 7:
         RandomTetrominoName = "Prefabs/Tetromino_Z";
         break;
     }

     return RandomTetrominoName;
  }

}

     and this is the tetromino script 

using UnityEngine; using System.Collections;

public class Tetromino : MonoBehaviour {

 float fall = 0;
 public float fallSpeed = 1;

 public bool allowRotation = true;
 public bool limitRoatation = false;
 

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {

     CheckUserInput ();
 }

 void CheckUserInput () {

     if (Input.GetKeyDown(KeyCode.RightArrow)) {

         transform.position += new Vector3(1, 0, 0);

         if (CheckIsValidPosition()) {

             FindObjectOfType<Game>().updateGrid(this);

         } else {

             transform.position += new Vector3(-1, 0, 0);

         }

     } else if (Input.GetKeyDown(KeyCode.LeftArrow)) {

         transform.position += new Vector3(-1, 0, 0);

         if (CheckIsValidPosition()) {

             FindObjectOfType<Game>().updateGrid(this);
             
         } else {
             
             transform.position += new Vector3(1, 0, 0);
         }

     } else if (Input.GetKeyDown(KeyCode.UpArrow)) {

         if (allowRotation) {

             if (limitRoatation) {

                 if (transform.rotation.eulerAngles.z >= 90) {

                     transform.Rotate(0, 0, -90);
                 } else {

                     transform.Rotate(0, 0, 90);

                 }

             } else {

                 transform.Rotate (0, 0, 90);
             }
                 
             if (CheckIsValidPosition()) {

                 FindObjectOfType<Game>().updateGrid(this);
          
             } else {

                 if (transform.rotation.eulerAngles.z >= 90) {


                     transform.Rotate(0, 0, -90);
                 
                 } else {

                     if (limitRoatation) {

                     transform.Rotate (0, 0, 90);
                   
                     }
                      
                     transform.Rotate (0, 0, -90);
                 }
              }
           }
                  

       } else if (Input.GetKeyDown(KeyCode.DownArrow) || Time.time - fall >= fallSpeed) {

            transform.position += new Vector3(0, -1, 0);

            if (CheckIsValidPosition()) {

             FindObjectOfType<Game>().updateGrid(this);
             
       } else {
             
         transform.position += new Vector3(0, 1, 0);

             enabled = false;

             FindObjectOfType<Game>().SpawnNextTetromino();
             
     }

     fall = Time.time;
 }

}

 bool CheckIsValidPosition () {

     foreach (Transform mino in transform) {

         Vector2 pos = FindObjectOfType<Game>().Round (mino.position);

         if (FindObjectOfType<Game>().CheckIsInsideGrid (pos) == false) {

             return false;
         }

          if (FindObjectOfType<Game>().GetTransformAtGetPosition(pos) != null && FindObjectOfType<Game>().GetTransformAtGetPosition(pos).parent != Transform) {

             return false;
         }
     }

     return true;
 }

}

if anyone can help me i would appreciate it thanks in advance

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Oct 31, 2015 at 11:00 AM 0
Share

The first error is not important, but could you separately paste the line of the second error? I can't find like this (there's no line 131 if that's it)

avatar image vespa39 · Oct 31, 2015 at 09:18 PM 0
Share

sure thing, sorry if it was a little long, thanks for responding. the 131 line is the if statement just above the last return false;

bool CheckIsValidPosition () {

     foreach (Transform $$anonymous$$o in transform) {

         Vector2 pos = FindObjectOfType<Game>().Round ($$anonymous$$o.position);

         if (FindObjectOfType<Game>().CheckIsInsideGrid (pos) == false) {

             return false;
         }

          if (FindObjectOfType<Game>().GetTransformAtGetPosition(pos) != null && FindObjectOfType<Game>().GetTransformAtGetPosition(pos).parent != Transform) {

             return false;
         }
     }

     return true;
 }

}

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Statement · Oct 31, 2015 at 10:22 PM

Short answer:
You are comparing vs a Transform type, not the transform variable.
Notice T and t is different.

Long answer:

 error CS0119:
 Expression denotes a `type', where a `variable', `value' or `method group' was expected

And then we have the snippet of code:

       if (FindObjectOfType<Game>().GetTransformAtGetPosition(pos) != null && FindObjectOfType<Game>().GetTransformAtGetPosition(pos).parent != Transform) {

Okay, that's one big sausage you got there. But I can spot the issue. Let me reduce the code so it becomes clearer.

 var game = FindObjectOfType<Game>();
 var atPos = game.GetTransformAtGetPosition(pos);
 
 if (atPos && atPos.parent != Transform)

Let's focus on the right side of the logical and operator &&

 atPos.parent != Transform

If it is not immediately clear to you, you're trying to perform a test between a Transform variable and the type Transform. This is what the error message says:
Expression denotes a type, where a variable, value or method group was expected

The typo is then obvious and it should be testing against transform.

 atPos.parent != transform

Then we can sausageify it back up the way it was with that simple fix.

       if (FindObjectOfType<Game>().GetTransformAtGetPosition(pos) != null && FindObjectOfType<Game>().GetTransformAtGetPosition(pos).parent != transform) {
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Oct 31, 2015 at 10:29 PM 0
Share

For the nitpicky, I don't really know what properties (transform is a property) are classified as for the compiler but I think where I use the word variable, it should be method group. Feel free to correct me so I learn something new today. :)

avatar image vespa39 · Nov 02, 2015 at 01:23 AM 0
Share

Thank you so much, that was the issue usually if i don't see an error when a word is spelled wrong i think i did everything correctly . have a great day @statement

Follow this Question

Answers Answers and Comments

33 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

ForcedScopedThreadAttach 0 Answers

C# Greater Than or Equal To 1 Answer

StartCoroutine error message in C# 1 Answer

Variable changing from other script does not work. 1 Answer

ArgumentNullException When using Collider2D.OverlapCollider() 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges