I need help with how to get rid of indentation error that comes in script files for no reason.
I know that there should be no identation error but I get it. It does not go away very easily.
Here is a screenshot-
I have to try really hard sometimes to get rid of this.
It feels like it is a bug.
Any suggestion on getting rid of this issue permanently?
We can't tell without seeing the previous lines. If that's inside a function at the root level of the script and isn't nested under some other expression, then it is indented one too far.
You are either indented to the wrong "level", or are using tabs and spaces interchangeably, which you can not do in Python. Post the whole scripts and we can help.
Right click in the editor space -> appearance -> whitespace. This should allow you to determine if you have mixed spaces and tabs. Also make sure you aren't missing any colons or brackets.
I found this post after having a bunch of problems with this. The suggestion to turn on Whitespace was the game changer. It makes things much easier to fix once you get used to linking the clues to the proper corrective action. I have a fair amount of code pasted from chatgpt, which I think is what got my script editor so messed up. I’m wondering if others have linked the cause to pasting code from there.
Agreed- The suggestion to turn on Whitespace was the game changer.
For me it is not copy paste.
It just happens. Even with the code that has been working. If i add a new line of code suddenly it starts erroring out. Especially if there is a commented line and i add a new line after that.
Just random.
I seem to have random indentation issues periodically. It looks correct, but the error persists. I can fix one line, and the issue moves to another line. When this happens, I paste into VS code, nudge all code right and then back left, then paste back into Ignition.