0

I'm asking if there's a way to essentially block off the rest of the program and only have access to a limited set of the program, for example

if speech.said("Lock"):
   Lock = true
   speech.say("Locked");

if Lock = true:
   [The continuation of this is my issue.] 

How do I continue this portion of the code? I'm completely new to Python as well, I've only had 3 days working with it. If you don't mind explaining thoroughly, any advice would be greatly appreciated! I'm making this with FreePIE, a programmable input emulator. It's much more flexible than the original GlovePIE, which has been discontinued, and Python is much more complex than I anticipated, I've been stuck on the lock issue for 2 days.. so literally anything is better than what I've got now, any simple solution to workarounds.

Thanks again, Austin.

acars123
  • 3
  • 3
  • *"block off the rest of the program"* Block it off from what? Are you doing multi-threading? Otherwise I am not sure I understand what you mean by "lock"?! – UnholySheep Nov 14 '16 at 23:01
  • Also pretty much none of that code snippet looks like valid Python code. `True` is written with a capital first letter and checking for equality is done via `==` not a single equal sign. And semi-colons are optional in Python as well. – UnholySheep Nov 14 '16 at 23:03
  • are you looking for a while loop? while (Lock): .... [some code that eventually sets lock to true] ? – AJ X. Nov 14 '16 at 23:03
  • @UnholySheep Ah, thank you for pointing that out, again, haven't had much time or experience with this language. I did know about == but didn't realize when it was needed, but the True part, really needed that, thanks, and essentially allow no input into other parts of the program, like disabling the rest unless you unlock it. – acars123 Nov 14 '16 at 23:29
  • @axlj I think that would work if I knew more about how a while loop functions. Haha. I'll look a bit into that more, thanks for the info. – acars123 Nov 14 '16 at 23:30
  • @axlj Does this look more functional? `def LockF: Lock == True def Unlock: Lock == False if speech.said("Lock"): LockF() speech.say("Locked"); while Lock == True: if speech.said("Unlock"): Unlock(); else: return False LockF();` – acars123 Nov 15 '16 at 01:05
  • You're on the right path, but if you're also trying to take input; you're probably going to do some multi-threaded work. What text to speech library are you using? – AJ X. Nov 15 '16 at 14:26

1 Answers1

0

Here is an example using python speech and a basic loop:

import string
import speech

locked = False

while True:
    print "Talk:"
    phrase = speech.input()
    if phrase.lower() == "unlock":
        locked = False
    if phrase.lower() == "lock":
        speech.say("Locked")
        locked = True  
    if locked: 
        continue
    print "You said {0}".format(phrase)          
    if phrase.lower() == "exit":
        break

In here, we loop infinitely until the user types 'Exit'. During the loop we:

  • check if the user requested an unlock, if they did we unlock
  • check if the user requested a lock, if so, we set lock to True
  • check if we are locked: if we are, we ignore the input and immediately restart the loop -- thats what continue means
AJ X.
  • 2,729
  • 1
  • 23
  • 33