erreurs soulignées

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.

Thanks for your help,

A+

This may help you with intellisense and possibly other Visual Studio integration problems:

Sometimes the fix is as simple as doing Assets → Open C# Project from Unity. Other times it requires more.

Also, try update the VSCode package inside of Unity: Window → Package Manager → Search for Visual Studio Code Editor → Press the Update button

Also, this: No suggestions in Vscode

Sorry, but I think it’s more a code error than a Visual Studio setting.

Unless it is used to debug the underlined words.

Kind regards,

A+

Hi,

I managed to debug the CoordCell and CreateTableau variables.
They had to be declared as static variables.

But I don’t understand why the debugger finds an error in Vector3

Thanks to you,

A+

What is CoordCell.varLeft ?

varLeft is a variable of a script that I call in another script (CoordCel).
But I have solved this problem.

What I want is to debug the Vector3 problem.

Thanks

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.

Good spot. There is an extra ) after the 27 that needs to be deleted.

First of all, don’t write code like that. Be kind to yourself.

How to break down hairy lines of code:

http://plbm.com/?p=248

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:

Imphenzia / imphenzia - super-basic Unity tutorial:

https://www.youtube.com/watch?v=pwZpJzpE2lQ

Jason Weimann:

https://www.youtube.com/watch?v=OR0e-1UBEOU

Brackeys super-basic Unity Tutorial series:

https://www.youtube.com/watch?v=IlKaB1etrik

Sebastian Lague Intro to Game Development with Unity and C#:

https://www.youtube.com/watch?v=_cCGBMmMOFw

What does the bug actually say?

it may be an script order issue.

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.

1 Like

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.

Your help is welcome,

A+

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.