Guys, is there any way I can make a script wait for a certain key to be pressed before continuing with the next part?
All I want to be able to do, if press F4 for the script to display the next item in the script, but not before.
I bet there's a real simple way to do this, only I can't seem to work it out.....
There are a few ways to get this done. Don't think of it as a few lines of code where you halt processing between lines. Instead make complete code statements that do what you want. The action of the button press triggers a script, verses continuing the processing of the current one.
alias key_ {
if (%key_x) {
;button has been pressed "continue script here"
echo -a Button has been pressed. What should I do?
;unset %key_x variable to be ready for next time.
unset %key_x
}
else {
;script starts
set %key_ $true
echo -a Im waiting for you to press the key.
}
}
alias f5 {
if (%key_) {
echo -a I waited for the key to be pressed and you just pressed it.
unset %key_
;acknowledge key has been pressed.
set %key_x $true
;go to command
key_
}
}
This is a bit crude and long winded. You really would just put the desired command in the F4 alias unless you had other plans.
As you can see, you type /key_. In the key_ alias, since the variable %key_x hasn't been set it skips to the else section where it sets a variable telling you and mirc that it is waiting for a key to be pressed.
When the key (F4) is pressed, if this variable wasn't $true it would do nothing. But since you told it to wait for they key press it will do the command.
What you want it to do when the key is pressed hasn't been stated, but you can put it in the F4 alias, or put it in the key_ alias as I have shown.
As you can see, it isn't as linear as you were visualizing it. You don't stop a script from processing, you break up the scripts. You can either make a new alias or make a new if statement in an existing alias. Remember you can't call an alias from within itself unless you use a timer.
Looking at things from different perspectives can be the biggest hurdle when scripting.