Give variables a default value in a function

  • I am writing a function in WorkVisual that takes some parameters and then performs calculations with them, returning the result. The actual code part is pretty simple; however, WorkVisual is giving me an alert warning me that my parameters are "used without checking [them] for correct initialization." How can I ensure that appropriate values are passed to my function, and if values are not passed (or a value of an incompatible datatype is passed), how can I override these values with "default" initializations?


    Thanks!

  • KRL doesn't provide any "default" values for incoming arguments, unlike some higher-end CompSci languages. However, you can include code inside the function to examine incoming arguments and act based on their values (or lack thereof).


    Assuming you are using a recent version of KSS, look at the module called MsgLib that comes in the robot by default. It uses a large number of ON_ERROR_CONTINUE statements to help accomplish what I believe you are looking for.


    There's also the VARSTATE system function.

  • Thanks! I've looked briefly at the VARSTATE function, it seems pretty powerful. I'll start incorporating it into my code to make it more robust.
    Kuka is funny with their functions, they have so much built in that no one realizes is there; I can't tell you how many pieces of code I've written (or rather, hacked together) in the last month only to find out like two weeks later that Kuka provides identical functionality by default (-:
    Ah, the exciting life of a robot programmer :winking_face:

Advertising from our partners