If-else statement in script

Hey everyone,
I am pretty new to using the UR interface and just had a quick question: I currently have a program which tells the robot to move to hole 1 through hole 4. At each hole I have a subprogram called to place the object the robot is holding in the hole. I had this idea to just have a for loop that goes 4 times and 1 script with an if-else statement. For example, if counter = 1: “go to this hole and increase counter” call subprogram, repeat. However, I am getting an error, and I am not sure why. Can I not put if-else statements in a script? Do I have to use the blocks? Maybe my syntax is wrong. I change the syntax multiple times but it does not seem to work. For reference, here is the error: “Compile error: An expression was found which produces a result that is not used in the program”
Thank you in advance

PS: This is a UR10e Robot

Here’s an example of an if . . . else statement from a random script we use:

if average_raw > -0.000025:
mult=1
else:
mult = -1

end

Pretty straightforward, but you need to make sure to have the colons. End statements can sometimes be optional, but I tend to include them to make sure.

Note - that error message is extremely generic. I’ve gotten that with syntax errors, capitalization mistakes, etc.

If you use a more sophisticated editor than Notepad or the UR editor, some of those mistakes may become more apparent.
I sometimes use Notepad++, which does a little bit of bookkeeping (matched parentheses, etc.) and has a compare file feature.

There are probably a number of editors which do a lot more when working with programs.

Here’s the link to the URScript manual which goes over all the commands and how to use them.

Everything avove is correct, but I’d lile to add some notes.

A robot program will always end with “end”. However, so does everything else. So if you wish to do an IF check, that IF also needs an END statement. Coming from super basic python this was really frustrating.

If you’re going to code in URScript, dowbload VSCode and the URScript addin for it, makes everything much better.

-Magnus