Hello to all,
I have some small errors in my code.
Indeed some words are underlined in red.
I use a variable of a script that I call in another script.
int iCellHorDiff, iCellVerDiff, Counter;
int iCellHorInPent, iCellVerInPent;
int iCellVer, iCellHor;
int i, j, Placed;
int NbObjetsPlaces;
void Update()
if (Counter == 5)
{
NbObjetsPlaces = NbObjetsPlaces + 1;
this.transform.Translate(new Vector3(CoordCell.varLeft + 10 + (iCellHor - iCellHorInPent) * 27), 0, CoordCell.varLeft + 10 + (iCellHor - iCellHorInPent) * 27);
Placed = 1;
for (i = 1; i <= 5; i += 1) ;
for (j = 1; j <= 5; j += 1) ;
if (CreateTableau.Tableau[i, j] == 1)
{
CoordCell.Grille[iCellVer - iCellVerInPent + i, iCellHor - iCellHorInPent + j] = 1;
}
}
{
As you can see on the image below (underlined text).
I don’t understand why the debugger highlights Vector3 and variables that are called from another script (CoordCell.varLeft or CreateTable.Tableau[i, j]).
I tried to declare the variables as public, but it doesn’t work.
Moreover, the CoordCell.varLeft variable does not work while the CoordCell.Grille variable works perfectly.
You can hover over the red underlying for a more detailed error message.
The best is to open the ‘Error List’ panel of Visual Studio, it will provide a list of all errors with the detailed text for each error.
If you do not have the ‘Error List’ panel opened, you can open it using the ‘View’ menu.
In your case, the text of the error message is: ‘Vector3’ does not contain a constructor that takes 1 arguments
You need 0, 2 or 3 parameters for the ‘Vector3’ constructor.
Note that if your Visual Studio is configured in French, the error message will be written in French.
Break it up, practice social distancing in your code, one thing per line please.
Second,
These lines do NOTHING. They are closed statements because of the semicolon.
Because of the defective loop declarations above, the above line is going to be executed ONCE, and most likely both i and j will be out of bounds because they’ve been iterated beyond their limit.
Third, don’t make class level variables called i and j. If you don’t understand why, then it is even MORE CRITICAL that you do not do this.
Finally it might be useful to just review how typical Unity scripting is used before wasting too much more time with the above. Here are some great coding tutorials:
Unless you mean “typed many of the wrong characters in the script in the wrong order,” I assure you that script ordering has absolutely nothing to do with the multiple errors I pointed out above.
Hello,
as you can see the CoordCell.varLeft and CoordCell.Grid variables are not underlined anymore.
(You should have declared the variables as public static int).
Now I have one last problem,
as you can see on the picture below (clicking on the picture), the word Vector3 is still underlined.
Seriously, this is basic C# syntax… please refer to line 14 in your original post at the top. You got it correct there.
If you still can’t see it, please don’t come here to have us look at each of your typos. Instead, learn how to read errors yourself and fix them. Here is how:
Remember: NOBODY memorizes error codes. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.
The complete error message contains everything you need to know to fix the error yourself.
Always start with the FIRST error in the list, as sometimes that error causes or compounds some or all of the subsequent errors.
The important parts of the error message are:
the description of the error itself (google this; you are NEVER the first one!)
the file it occurred in (critical!)
the line number and character position (the two numbers in parentheses)
All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.