# Debugging in URScript

**URL:** <https://forum.universal-robots.com/t/debugging-in-urscript/128>\
**Category:** URScript\
**Created:** [July 21, 2016, 12:00pm UTC](https://forum.universal-robots.com/t/debugging-in-urscript/128 "2016-07-21T12:00:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [July 21, 2016, 12:00pm UTC](https://forum.universal-robots.com/t/debugging-in-urscript/128/1 "2016-07-21T12:00:37Z")

</div>

URScript is a language developed by UR, which has many similarities to Python.

All functions are explained in the script manual.

URScript is not a compiled language, thus an error will first occur when it is executed, in contrast to e.g. C or C++ where the compilation will discover the error.  
Thus, your script program can run until an error (syntax error or similar) occurs.

Two simple ways of debugging your script code might be:

1. Using global step-counter variables
2. Writing status messages to the logfile

**1) Step-counter variables**  
Using global dummy variables in your program makes it possible to see the progress in the Variables tab in PolyScope.  
If you have a script code like:

```auto
global DebugStatus = "Start of script code"
def function1():
   # Some function definition
end
global DebugStatus = "Function 1 defined"
def function2():
   # Some function definition
end
global DebugStatus = "Function 2 defined"
function1()
global DebugStatus = "Function 1 executed successfully"

```

Thus we are using the `DebugStatus` string variable to show how far the execution of the script code has gotten.  
When the variable is declared as `global` it will be shown in the “Variables” tab in PolyScope.

When the code is operational, the variable can be deleted from the script program.

**2) Using the logfile for debugging**  
The script code `textmsg()` sends a string message to the logfile of the robot.  
It is convenient when you have a variable, that you would like to declare and store the result of for debugging, this function can be useful.

You might have a script code like:

```auto
def function1():
   socket_open("127.0.0.1", 33000, "my_socket")
   var1 = socket_read_ascii_float(3, "my_socket")
   textmsg("var1 read as: ", var1)
end

```

In the logfile and thus also the Log tab, you might now read:

```auto
YYYY-MM-DD HH:MM:SS.sss RTMachine var1 read as: [3, 1.23, 2.34, 3.45]

```

Hence, `textmsg()` is useful for storing replies from a socket connection or a measured variable that might soon be overwritten.

**Note:**  
Remember to remove the `textmsg()` in your operational script code.  
Many unnecessary writes to the log file makes it less readable and uses unnecessary disk space.

---

<div class="post-metadata">

**Author:** ![ellingsen.harald](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/ellingsen.harald/32/1116_2.png) [@ellingsen.harald](https://forum.universal-robots.com/u/ellingsen.harald)\
**Post date:** [October 21, 2020, 9:07am UTC](https://forum.universal-robots.com/t/debugging-in-urscript/128/2 "2020-10-21T09:07:26Z")

</div>

@jbm  
Ref. your reply above regarding unnecessary use of disk space. is the output from textmsg() saved to a file on disk? In case which file is this logged to? I cannot find this logged anywhere.

---

<div class="post-metadata">

**Author:** ![sam.verity-hilton](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/sam.verity-hilton/32/6046_2.png) [@sam.verity-hilton](https://forum.universal-robots.com/u/sam.verity-hilton)\
**Post date:** [October 21, 2020, 9:24am UTC](https://forum.universal-robots.com/t/debugging-in-urscript/128/3 "2020-10-21T09:24:33Z")

</div>

The easiest way to access the log file is to download the support file. This button can be found in the log screen, and will save a backup of all sort of things, one of which will be the log file, containing everything that was printed to the log including anything sent via `textmsg()`. The file you are looking for is called `log_history.txt.`
