Help with bind and event

Need help with a macro you are writing? Ask here!

Moderator: MacroQuest Developers

dedw8
decaying skeleton
decaying skeleton
Posts: 6
Joined: Wed Aug 11, 2004 3:10 pm

Help with bind and event

Post by dedw8 » Mon Aug 16, 2004 10:13 am

I'm thinking this is a very simple thing to do yet in searching through all the posts and reading the manual I can't seem to figure it out. I'm writing my first macro and trying to do the following:

After I start my macro I want it to detect every time I press a key, say the 'e' key. I'm thinking I need to use events but not quite sure.

Any help is truly appreciated, and sorry if this is a dumb question.

Thanks,
D

User avatar
fearless
Not a Psychic
Posts: 2684
Joined: Wed Mar 10, 2004 3:52 pm

Post by fearless » Mon Aug 16, 2004 11:36 am

This type of thing has usually been done with the varset command.

IE you would have an if statement with if varset = 0 then do this, if varset = 1 then do that.

Then you do an /echo varset 0 or /echo varset 1 to change the behavior.

The next step would be to use either a hotkey with the two echo's in it, or you could use a keybind.

Sorry for lack of better examples, but it should give you something to start searching for.

User avatar
Fuergrissa
a grimling bloodguard
a grimling bloodguard
Posts: 607
Joined: Mon Dec 08, 2003 3:46 pm
Location: UK

Re: Help with bind and event

Post by Fuergrissa » Mon Aug 16, 2004 11:41 am

dedw8 wrote:I'm thinking this is a very simple thing to do yet in searching through all the posts and reading the manual I can't seem to figure it out. I'm writing my first macro and trying to do the following:

After I start my macro I want it to detect every time I press a key, say the 'e' key. I'm thinking I need to use events but not quite sure.

Any help is truly appreciated, and sorry if this is a dumb question.

Thanks,
D
Could you give me an example of Why you would want to do it, maybe there is a better way to accomplish your goal.
[quote]"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."[/quote]

User avatar
Cr4zyb4rd
Plugins Czar
Posts: 1449
Joined: Tue Jul 20, 2004 11:46 am

Post by Cr4zyb4rd » Mon Aug 16, 2004 12:45 pm

Several ways to do this. If there's a behavior in your script that you want to trigger or toggle, you can do this.

Code: Select all

/custombind add ToggleEKey
/custombind set ToggleEKey /varset EKey ${If[${EKey},0,1]}
/bind ToggleEKey e
be sure to

Code: Select all

/declare EKey bool global 0
in your macro or config files. If there's some behavior you want to continue WHILE you have the key held down, and then stop as you release it, use

Code: Select all

]/custombind add ToggleEKey
/custombind set ToggleEKey /varset EKey 1
/custombind set ToggleEKey-up /varset EKey 0
/bind ToggleEKey e
instead.

You could also do something like

Code: Select all

/custombind set EKeyStuff /echo Please do the EKey stuff now.
and then in your macro

Code: Select all

#event EKeyHit [MQ2] Please do the EKey stuff now.
Sub Event_EKeyHit
 blah blah blah
/return
to make an event, but this will spam your MQ window whenever you hit a key. Something like this could also be done using timers.

Either method will also work if you want to queue up multiple events, like "nuke 4 times if I spam the key 4 times", just use some '/varcalc EKey +1' action in there somewhere, and reduce the counter each time you handle the event.

dedw8
decaying skeleton
decaying skeleton
Posts: 6
Joined: Wed Aug 11, 2004 3:10 pm

Post by dedw8 » Mon Aug 16, 2004 1:46 pm

You guys are great. Someone asked for an example of what I'm trying to do, here goes:

1. Start my macro and wait for 'e' to be pressed
2. Every time 'e' is pressed do a certain action (I have an array of actions, so each 'e' press goes to the next, at the end of the array it goes back to the beginning)
3. I will manually terminate my macro.

I've got everything done save for the capture of the 'e' key, but wasn't sure if I would need a doevent loop and use bind or not.

I think Cr4zyb4rd is on the right track for what I need but its not a toggle, more capturing a keystroke to fire some code.

This confused me a little as well as i'm not quite sure whats happening after the varset:

Code: Select all

/custombind set ToggleEKey /varset EKey ${If[${EKey},0,1]}
Thanks again,
D

User avatar
Cr4zyb4rd
Plugins Czar
Posts: 1449
Joined: Tue Jul 20, 2004 11:46 am

Post by Cr4zyb4rd » Mon Aug 16, 2004 3:13 pm

If the value of ${EKey} is other than 0, set it to 0. Otherwise set it to 1. (ie toggle the value between true/false)

JP5
a lesser mummy
a lesser mummy
Posts: 70
Joined: Tue Jul 06, 2004 10:32 pm

Post by JP5 » Wed Aug 18, 2004 3:58 pm

If you have an array, wouldn't you want to have values from 0 to ${ArrayName.Size} ?

If that's the case, here is what I would do.

Code: Select all

/declare ET[n] int local 0

/custombind add EToggle
/custombind set EToggle /docommand ${If[${ET}==${ET.Size},/varset ET 1,/varcalc ET ${ET+1}]}
/bind EToggle E
If ET array is at max, it sets it back to 1 (i'm not sure if you wanted it set to 1 or 0, so change that if it isn't right)