, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here
Is there a command or other way for a script to check the Pause state of the Speech Recognition or Personality controls? I want to keep a PauseOff command in a script from running for these two controls if they are already paused?
For example; I have several scripts written that turn on and then off these two controls while the scripts are running. I also have a button on the outside of the robot that's attached to an ADC port on EZB that I also use to toggle these controls Pause on and off. If I've activated the pause on either control using the external robot button through the ADC port I'd like to add lines to my other scripts that will check to see this state. Basically I don't want those scripts turning off the Pause if I've already turned it on.
I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.
Also, consider reviewing the Learn section for informative lessons and activities.
Check it out!
You can set a variable to keep track of whether Speech or any other control is active or paused... For instance....
Speech Recognition PauseOn
Speech Recognition PauseOFF
You can use the value of $x in other scripts to determine whether the control is on or has been paused...
OK, so would it look something like this:
I could define and set the variable in the Button/ADC script that first turns the Pause on or off. Then in the following scripts that would have a pause command I'd also need to place a check on this variable to see if it's on or off with an "If" and "Elseif"?
Could I possibly set these variables in my "Int" script that first run when EZB first starts?
Still trying to wrap my head around coding. I kinda thought I could use a variable for this but just couldn't work out how to make it happen.
I usually set my variables in my connection control script .... So the second I connect everything is initialized including whether I want my speech recognition control set to be paused or set to be on... for example
then as you turn on and off your controls via scripts you set the $speech and $personality accordingly... Then use if statements as you mentioned to check if the variables $speech and $personality is 1 or 0.... This is a good way to determine if you have already set the controls on or off in another script...
So something like this....
if $speech=1 #speech control is un paused
speechControlPauseOn # then pause it
Next time this code is run the speech control is already paused (the $speech flag is set to 0) so the if statement will return false and won't try and pause it a second time...
Thanks Richard! This example and explanation makes it easy to understand. It's good to have you here on the forum and so willing to share your talent and knowledge.
Ha, Ha thanks Dave... It's a 2 way street though, dude... I always appreciated your fabrication and mechanical skills....
Well I've gotten the Variables and script written. Wow, I can't believe how elegant this is and how well this works! It wasn't really such a hard concept to understand and work into my project once I thought it through. However I was surprised at how my befuddled mind farted around with it till I worked it through in the scripts and reread your suggestions @Richard.
The Flag comment is what helped me sort it out. I thought I had a good idea of how a variable worked but that's just it, a variable does not work. The way I understand it now is that It's just a bookmark of sorts, a simple value, a marker or a "flag" as you put it. The script just uses this value as a target or sign post for direction.
Anyway, I set the "flag" to whatever will tell the script is the proper On or Off value of the state of the Voice or Personality Pause. In my case; 0 for Pause, 1 for Unpause.
The script that runs when I push the button on the robot that's attached to a ADC port to toggle the Voice Recognition or Personality Generator script on or off will change the Variable to "0" when I first push it. Then an ADC_Wait() command will hold the script till the button is pushed again and the variable will again change to 1
In the mean time I can run other scripts that have a couple "If" statements in them looking at these variables and depending if it sees a "0" or "1" will pause either or both of the Voice Recognition or Personality Generator.
Simply amazing. Thanks so much for the guidance!
Ez Builder is a awesome tool to learn logic programing... I knew how to program before in other simple programming languages, but nothing complicated.... However, because I learned so much with EZ Builder, It has helped me take a stab at C (programming Arduinos)...
A little tip about variables... I have a bad habit of using short variable names like $x.... later as my program grows and evolves I end up scratching my head trying to figure out what I originally used $x for... Good practice is to instead use a variable name that represents what you are using it for... For example $PersonalityFlag or $PerFlag.... That way later when you come back to a script you know what the $PerFlag is for....
Like you, I do like fabricating, although I am not quite as skilled as you so I opted to use kits like Vex... Anyway, programming is just as awesome and a great way to express creativity.... Dave, you built an amazing bot.... If you dig into programming you can really make him come alive....
Just had an idea... Rich or DJ, if you're listening... I see a book on using EZB and EZ Builder down the road... I mean, why not "Programming the EZB with EZ Builder"? Arduino has a ton, EZ Robot is due...
Already thought about it dude
But with the speed at which things change, plus the V4 and Revolution being announced I put a hold on what I was throwing together.
When I have more time I intend on getting back on to some type of unofficial EZ-B/EZ-Builder/EZ-Script for dummies style book.