Erroneous Error line number + missing label

Hello,
Have been receiving sometimes an erroneous line number in the script code debugging:

In this particular example, I only have 226 lines of code (as per UR Editor + notepad), but it reports 256…
Since there is no label, I am unable to know which line it is refering to specifically. Most of the time I do get a label though, so I wonder why there is none this time.

Thanks

@gbS,

The line referred to in the popup is the script line in the executed program, which is the script file concentrated into the existing UR program.

As an example:
If you create a script code like:


There is an error on line 4 since var = p[0,1,2,3,4] = 1 is illegal. (Double assignment + poses must be initialized with 6 numerics).
However, when I am executing my program, I am getting this error:

Thus, the error is stated at line 32.

This happens because the script file myscript.script just contributes it’s script code to the program script code.
My program “linecounter” is saved as a .URP file (UR program file), but also as a .script file, representing what script code the program eventually is translated into.
By opening the file linecounter.script I can read my actual code:

Hence I can see, that in the beginning of my script file, a lot of commands are coming from the Installation settings (TCP setup, payload, contributions from URCap installation nodes…).
The script from myscript.script is appended to the program from script line 28 to 34, why the actual error that URControl/RTMachine reports is on line 32.

I see!
But then my main robot program is 255 lines long, and the error is about line 256, which does not contain anything and would explain the empty label, but not what it is flagging.

From the script code I can see that you have a double function definition.

E.g. if your program is named “myFunc”.
You create a script code that defines a function that is called def myFunc():
Thus, when you save your program, both your program and your script function has same name:

def myFunc()
   # installation stuff
   $1 RobotProgram
   $2 scriptcode.script
      def myFunc():
         # some code
      end
      myFunc()
end

Hence, when you are calling myFunc() in the program, you are re-defining the function and calling the function itself.
This is however not the one creating the error, this is just a dangerous practice.

In your code you have an if/else-if function like:

def function(code):
 if code==0:
  #do something
 elif code==1:
  #do something
 elif code==2:
  #do something
 elif code==3:
  #do something
end

Thus, you are one endshort at the end of the if/else-if branching.
Inserting the end finishing the elif-statement resolves the error.

The reason why the syntax error comes at the last line is, that the main program in case of a missing end is missing the end-command.

Thus:

def main_program():
   #installation stuff
   def program():
      def subprogram():
         if something:
            #code
         elif something_else:
            #code
         # this is where an `end` command is missing to finish off the if-elif
      end # actual end of if, but should be end of subprogram()
   end # actual end of subprogram(), but should be end of program()
end # actual end of program(), but should be end of main_program()
# missing end of main_program(), thus error on last line