Ability to check if a variable is initialized to a value

I would like the ability to check to see if a variable is initialized so that if it’s not I can enter the default value or execute a script command for example to fetch its value from a server via RPC. This affects variables that are marked as remember last value specifically. They do not always remember their last value between shutdown and start up.

For instance in this program we have a flag to verify that all data was transmitted before the program stopped due to a fault or the user stopping the program prematurely. If not, at the top of the next program we resubmit the data to the sever.

In other languages you are able to check to see if a variable has been initialized prior to using it so you can initialize it

Hi Matt

In what scope are you looking for this ability?

Would this be in URScript, or would you like to assess this information from inside a URCap (hence in Java)?

Within URScript

Matthew Bush
Hirebotics
M: ‭(615) 479-6151‬

Hi Matthew

Do you mean the ability to write back some data to installation files?

No, I want to be able to query a variable at the top of the program and determine if the variable has been instantiated and has a current value assigned to it, basically know that it is not null.

Here is an example of what I am looking for from nodejs.

if (!thisNewVariable){
   console.log('The variable \'thisNewVariable\' does not exist')
   var thisNewVariable='Hi There'
}

console.log(thisNewVariable)

If you run this in the terminal you would get the following output:

The variable 'thisNewVariable' does not exist
Hi There

If you try the same thing in URScript you just get that the variable does not exist and the program exits. As mentioned in the request, we have times where the value that is supposed to be remembered is not being remembered between sessions. This would allow us to check at the top of the program and if the variable does not exist we could assign a default value to it initially. The issue is when customers are. running the robot in RUN MODE versus us being on site and in Program Mode where we can easily fix it.

Only the Installation variables are physically stored to disk between shutdowns.
However you can only be certain of this, if the user shuts down the robot correctly.
If holding down the power button to shutdown, or pulling the plug - which both are very bad practice - you are not really certain the values are stored anyway.

The various options in your program where you can ask a variable value to be persistent between program runs, are not certain to be kept between shutdowns, since the value is only stored to RAM.

I reckon using Installation variables when possible, is the way ahead, if you want to store the value.
If you use implicitly defined values like a cnt_1 value from Palletizing, you cannot assign this as well as an Installation variable, as the name would be “taken” and Palletizing would then name its variable cnt_2.
In this case you should then initialize cnt_x with a saved Installation variable when the program starts, and constantly latch the new value of cnt_xback to the Installation variable copy.