homepage

Doing something based on current mode

Posted By: WileECoyote

Doing something based on current mode - 11/06/11 01:39 AM

Hello gentlemen.

I'm trying to do something pretty easy... but I don't seem to be able to.

What I want is combine the mode switch (button 3) with a keypress, so I can send a keystroke to the sim and at the same time switch to another mode on the stick.

So, for example:

I´m in mode 1 (NAV), and then press button3, to go to my AG mode, then stick not only switches to mode 2, but also sends Shift-6 to my sim. Obviously, to be able to know what key to send, I first need to know what mode I'm in. I would think that I can query the CURRENTMODE variable, something like this:

Code:
if (JS1.b3) then
  if (CURRENTMODE == MODE1) then
    SendKey('Shift-6') <--- No idea how to do that.
    CURRENTMODE= MODE2
  else if (CURRENTMODE == MODE2) then...


But I'm getting the error: "Bit value expected but CURRENTMODE found"...

Any idea about how to accomplish this?

Thanks.
Posted By: 531 Ghost

Re: Doing something based on current mode - 11/06/11 02:10 AM

Sounds like you may be looking for a IF/THEN/ELSE ?
Posted By: WileECoyote

Re: Doing something based on current mode - 11/06/11 02:16 AM

Thanks Ghost, but nope.

The problem is the evaluation per se, the if (CURRENTMODE == MODE1) part. I played around with the if statement and have no problems with it. The problem comes when trying to evaluate the CURRENTMODE variable.
Posted By: 531 Ghost

Re: Doing something based on current mode - 11/06/11 03:46 PM

banghead That'll teach me to skim over the obvious!

Sorry

Yes, it is easy and no need for scripting actually. Follow along...



"gove" fat fingerd that one... biggrin







Now, simply do the same for modes 2 and 3 with the desired keys/macros and you'll be set with NAV/AA/AG modes. All you'll have to do is look at the LED on the base of the FighterStick. For me, I use Green = NAV, Red = AA and Amber = AG
Posted By: WileECoyote

Re: Doing something based on current mode - 11/06/11 04:23 PM

Ah, thank you very much mister Ghost. But still... yeah, I know... I´m still getting headaches with this. The problem now is that I can't seem to get a proper sequence out of this.

I followed your mini tut, and asigned the keys 4, 5 and 6 to each mode. Now when I press then, I get kind of random failures, for instance, 456456446564564565456. Any idea what could cause it. My first thought was that I was pressing the keys to quickly when testing them, but nope, even if I press them with enough between each other, the problem persists.
Posted By: Bob Church

Re: Doing something based on current mode - 11/06/11 10:14 PM

Hi WileECoyote,

I'm assuming you've moved to Ghost's method, just programming the character to the Mode button (3) directly. It creates some timing problems, there are just too many "clocks" running asynchronously and it's easy to pick up a repeating character or a character coming for the wrong mode. It's not usually a problem because when it's a separate button the mode change is usually complete before the character gets sent. You might still get a duplicate now and then, but there's no more risk than with a normal press.

It's actually an easy thing to fix. You need to force the character to not repeat and you need to force it after the mode change is completed. Program it as Ghost says, but for Button 3 put:

NULL

in for the Normal "Press" character on all three Modes, and then put the character(s) you want to send in the Normal "Release" box. The mode changes on the press, so it's always complete when you release the button (if it registers at all), and seems to clear things up when I run it here.

Give it a try and see if it will work for you!

Best regards,

- Bob

The StickWorks
http://www.stickworks.com
Posted By: WileECoyote

Re: Doing something based on current mode - 11/07/11 12:50 AM

Absolutely perfect. Thank you for the help. bananadance
Posted By: Bob Church

Re: Doing something based on current mode - 11/07/11 01:56 AM

Hi WileECoyote,

You're quite welcome! I'm glad it was some help!

Have fun!

Best regards,

- Bob

The StickWorks
http://www.stickworks.com
Posted By: 531 Ghost

Re: Doing something based on current mode - 11/07/11 12:49 PM

Originally Posted By: Bob Church
It's actually an easy thing to fix. You need to force the character to not repeat and you need to force it after the mode change is completed. Program it as Ghost says, but for Button 3 put:

NULL

in for the Normal "Press" character on all three Modes, and then put the character(s) you want to send in the Normal "Release" box. The mode changes on the press, so it's always complete when you release the button (if it registers at all), and seems to clear things up when I run it here.



Should've tested in my test.map, thanks Bob!
Posted By: Bob Church

Re: Doing something based on current mode - 11/07/11 07:28 PM

Hi Ghost,

Yer welcome! It's just a little tricky, things can get out of order pretty easily. When I ran the map, I saw just what he described, but looking at it I could see that it was just not switching modes in time or getting a duplicate and I guessed the characters weren't blocked from repeating on the press side. I played around a bit and it was just an easy way to handle both. The press side always switched the mode first and the release side always acts like there's a NULL after it to stop the repeat, so it just all fit together. The only way I've been able to get a glitch out of it was working button 3 very rapidly. Sometimes that can cause it to skip, I think you end up just changing modes before it has time to react, but so long as the button gets a solid click it seems to be unbreakable. You could probably work around even that with a little CMS file and flag or two, but I don't think it's really a problem in any case.

Anyway, a handy trick for the few times you want to send something and change modes at the same time.

Best regards,

- Bob

The StickWorks
http://www.stickworks.com
Posted By: OlafM

Re: Doing something based on current mode - 11/14/11 07:10 PM

Hi WileECoyote,

Concerning
Originally Posted By: WileECoyote
But I'm getting the error: "Bit value expected but CURRENTMODE found"...


The error appears because you forgot to wrap the numeric comparison with brackets. Like this:
Code:
if ( [ CURRENTMODE == MODE1 ] ) then
...
endif


CMS just works a little different than "normal" programming languages.
Posted By: WileECoyote

Re: Doing something based on current mode - 11/15/11 01:53 AM

Oh, that's great. Thanks OlafM!
© 2024 SimHQ Forums