The question is answered, right answer was accepted
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
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)
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;
}
}
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) {
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. :)
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
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