Home Programming

Discussion

Left ArrowBack to discussions page
PMonfortePMonforte Posts: 2 Recruit
Greetings DoF community,

I am trying to write an if-statement in an URscript but I haven’t been successful.
Before the if-statement, I have this while loop:

while(get_standard_digital_in(0) == False):
sleep(0.01)
end
This loop works perfectly. I thought the same method would apply to the if-statement but after many tries, I am not able to run the code. This is what I have now:
if(get_standard_digital_in(0) == True):
var_1 = True
end
Before the while loop I have:
global var_1 = False
Unfortunately, this code does not run with the if-statement, even though it runs fine without it so the trouble is definitely in how I am writing it. Any help is much appreciated.
Best regards,
Pedro Monforte

Comments

  • bcastetsbcastets Vacuum Beta tester Posts: 653 Expert
    You should be able to simplify the code:

    while(get_standard_digital_in(0) == False):
    sleep(0.01)
    end

    Can be written:

    while not get_standard_digital_in(0) :
        sleep(0.01)
    end

    Also you should be able to write:

    If get_standard_digital_in(0):
        var_1
    end

    The code looks correct to me. Maybe there are some details that can only be seen by looking at the complete script.
  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,266 Handy
    As @bcastets said, the if statement looks right, nothing wrong that should cause the script not to run.  I will add another simplification to the script.

    while not get_standard_digital_in(0):
      sleep(0.01)
    end
    var_1 = get_standard_digital_in(0) # This will set to True if the input is on, False if it is off eliminating the need for the if statement

  • PMonfortePMonforte Posts: 2 Recruit
    Thank you very much for the replies. I have found a solution. For reasons I know not, the program does not run with this:
    if(get_standard_digital_in(0) == True):
    var_1 = True
    end
    However, if I do this, 
    if(get_standard_digital_in(0) == True):
    var_1 = True
    sleep(0.01)
    end
    it works perfectly.
    Thank you very much for your replies
Sign In or Register to comment.
Left ArrowBack to discussions page