View Full Version : Quirk about the KEYS command
MFreywald
23-04-2005, 02:42 PM
Something I just noticed today is that the KEYS command doesn't work with CMC files. In other words...
KEYS +Fire -Fire +Alt_Fire -Alt_Fire
generates a 'Invalid or unrecognized command FIRE' (ALTFIRE...etc). Seems to disregard the _ also. Now this makes perfect sense but just wondering if it's a known issue or not.
MFreywald
Bob Church
23-04-2005, 03:15 PM
Hi MFreywald,
Well, it's "known" but it's not really an "issue". The KEYS thing was meant to let you map indifvidual keydown and keyup events when none of the normal programming methods could do what you needed done. It was really just never intended to process CMC commands, etc. Just a way to tell the CM that "now this key goes down, now that key comes up,..." etc.
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
MFreywald
23-04-2005, 06:08 PM
I kinda figured as much. The only reason it came up with me is I'm going through and either using the already created CMC's here (thanks Michael!). Or creating my own for the various maps I've made. One in particular has need of the KEYS command, UT2004. I setup a button that will switch to translocator - fire, then on release it would alt-fire then switch back to the last weapon. like so...
Pressed: KEYS +q +b -q
Released: KEYS -b +n -n +e -e
And since I was trying to clean up my mappings I tried to CMC alias the keys and alas..
On a side note.. Can anyone think of a way to get it to do something like this. In scripting of course. This is just psuedo code.
Switch to translocator
Fire translocator
Alt Fire tranlocator
Check if the shift button is pressed
if no then switch back to last weapon
if yes then keep the translocator
Trying to work out a way to quickly translocate around then switch back when i'm done. The way I have it set up now, there's too much of a delay when it switches back and i wanna use the translocator again. If I could keep it selected while the shift button is held then switch back when i release the shift button I think that would be ideal.
MFreywald
abe_beson
23-04-2005, 10:43 PM
Hi!
I never played UT so I'm not sure of what you mean by all this, but I am pretty convinced that you could use a number of sequences in your script to accomplish what you want. In the following I will make the assumption that you want to press just one key to run all your pseudo code and have it keep running while you are holding the shift key down. I have also assumed that you have one key to switch to and from translocator mode and one key each to fire translocator and alt translocator. This is what I would do:
// CMS Script File
//
// Â* Â* Game Title:
// Â* Â* Written By:
// Â* Â* Â* Â* Â* Date:
//
%define translocator Â* Â* Â* Â* Â* Â* Â* Â*b1
%define inTranslocatorSequence Â* Â* Â*b2
%define inEndTranslocatorSequence Â* b3
%define translocatorKey Â* Â* Â* js1.b1
%define shiftKey Â* Â* Â* Â* Â* Â* Â*js1.b3
%define switchTranslocatorOut Â* cms.b1
%define FireTranslocatorOut Â* Â* cms.b2
%define altFireTranslocatorOut Â*cms.b3
script
Â*sequence
Â* Â*wait(translocatorKey
Â* Â* Â*&& NOT inEndTranslocatorSequence); // Waits until the key is pressed and the sequences are finished
Â* Â*delay(1);
Â* Â*translocator=true;
Â* Â*// Push the switch to translocator key
Â* Â*switchTranslocatorOut=true;
Â* Â*delay(2);
Â* Â*switchTranslocatorOut=false;
Â* Â*delay(2);
Â*endSequence
Â*
Â*sequence
Â* Â*while(translocator);
Â* Â*inTranslocatorSequence=true;
Â* Â*FireTranslocatorOut=true;
Â* Â*delay(2);
Â* Â*FireTranslocatorOut=false;
Â* Â*delay(2);
Â* Â*altFireTranslocatorOut=true;
Â* Â*delay(2);
Â* Â*altFireTranslocatorOut=false;
Â* Â*delay(2);
Â* Â*inTranslocatorSequence=false;
Â* Â*delay(1);
Â*endSequence
Â*sequence
Â* Â*wait(translocator);
Â* Â*inEndTranslocatorSequence=true;
Â* Â*wait(NOT shiftKey AND NOT inTranslocatorSequence);
Â* Â*translocator=false;
Â* Â*InTranslocatorSequence=true;
Â* Â*switchTranslocatorOut=true;
Â* Â*delay(2);
Â* Â*switchTranslocatorOut=false;
Â* Â*delay(2);
Â* Â*inEndTranslocatorSequence=false;
Â*endSequence
endScript
Feel free to modify it if I did the wrong assumptions, but remember that the three sequences should be considered running in parallel and that is fairly easy to end up in a deadlock. If that happens just switch from mapped to direct mode in the controlmanager, if that doesn't work unplug your device.
Good luck,
Abe
Bob Church
23-04-2005, 11:41 PM
Hi MFreywald,
Well, you can define the CMC command in terms of a KEYS statement which might clean it up a bit. In fact, if you right click in the CMC editor screen, the recorder dialog will run and set things up for you. You might have to edit the "+b/-b" things once you were done but it would do most of the work. Anyway, you'd need two definitions one for press and one for release, and they'd have to use only the KEYS statement in the definition like:
TranslocatorPress = KEYS +q +b -q
TranslocatorRelease = KEYS -b +n -n +e -e
which would clean the way things looked in the GUI at least. They'd have to be the only commands assigned, you couldn't assign anything else to a the button that triggered them. You'd need to be sure to include the release side or you'd stick the "b" key, too, but it does work. It's just trying to define the KEYS macro in terms of other CMC commands that causes the problems.
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
MFreywald
24-04-2005, 02:19 AM
Hehe....man, sometimes we can think of the most complicated stuff for something that is actually very simple. It was very simple really.. heres what I did..
[Normal]
Pressed: KEYS +q +b -q
Released: KEYS -b +n -n +e -e
[Shifted]
Pressed: KEYS +q +b -q
Released: KEYS -b +n -n
That's it! I checked it and it works as needed. If I say for instance press the button without the shift and then press the shift while keeping the button pressed then release the button still holding the shift..it does send the shifted release. And Vice versa.. If i press the button while holding the shift then let go of the shift while still holding the button then release..it sends the unshifted release. Which opens up a whole new avenue for me cause I never really thought of using the shift to change states mid-press/release.
Thanks abe for the code snippet. While it turned out to be easier than that, your code did give me some ideas unthought of before.
Bob,
Ah..ok, that makes sense and would indead clean up the code. would I be able to use 3 definitions? one for the pressed (same for both normal and shifted) and a different definition for the released in the normal and shifted? as in..
[Normal]
Pressed: Translocator
Release: Translocator_Switch
[Shifted]
Pressed: Translocator
Release: Translocator_Keep
Of course I'll try it out to see. But if it doesn't a brief explanation would be helpfull as to why it wouldn't work.
MFreywald
Bob Church
24-04-2005, 02:55 AM
Hi MFreywald,
>> would I be able to use 3 definitions? <<
Sure. Just so they only use KEYS on the right side and you set it up so that you always get the release characters. Sending "+b" without a "-b" sometime down the line will stick the "b" key. The CM takes care of that for you in with the normal things, but I don't think it does (or can) with the keys macro, which would be in line with your observation about changing shift in midpress. You've got the "-b" in both release strings so you should be okay, but you need to make sure that anything that "makes" on either press does a "break" on either release. You can include extra breaks, though, so if you have to just tag in a "-b". For example, if you had two presses:
KEYS +b +c // Normal
KEYS +b // Shifted
and then two releases:
KEYS -b -c // Normal
KEYS -b // Shifted
you'd have trouble with a stuck "c" if you pressed it as Normal and released it as Shifted. Make both release strings:
KEYS -b -c
The extra "-c" for the shifted release wouldn't hurt anything. In the end, unless the "c" was down, the release really does nothing. If the "c" is down, the second command will break it. The one you've done is fine, it's got "-b" both places, but it can be a problem sometimes.
BTW, I made a slight typo in the first post, I put "=" signs in the first post between the name and the definition, those actually shouldn't be there. They should just be:
TranslocatorPress KEYS +q +b -q
TranslocatorRelease KEYS -b +n -n +e -e
in the CMC file. Sorry about that.
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
MFreywald
24-04-2005, 03:06 AM
Welp, after testing it out.. It worked in practice in the key check.. but in game I'm finding that it's still not what I'm looking for per say. Once in game I realized what I'm needing is for the shift button to send the 'switch back to prev weapon' command. The reason is, is..while running around and shooting off the translocator, I'm finding that i wanna keep the translocator untill I release the shift button. So if I've done a press and release of the button but still have the shift pressed. Upon releasing the shift I want it to switch back. My biggest problem with this though is I use the shift for other buttons so I can't put any command definitions in it per say. I'm trying to work it out in scripting right now. But wanted to take a second look at Abe's script cause it might actually be what I need.
MFreywald
MFreywald
24-04-2005, 03:22 AM
Abe, Your script actually is what I'm looking for after all.. Only one problem that I see off hand is the delays. The way it works is, the little pod that comes out keeps going as long as I'm still holding the fire button. Once I release the fire button it lands and then alt-fire puts me where it is. So there needs to be someway to determine when i've released the fire button after I've pressed it. And use that as the trigger to start the other checks. To make it a bit less cryptic I'll define the keys for you that i'm using in my KEYS command.
q = Switch to translocator
b = fire
n = alt-fire
e = switch to prev weapon.
so as you can see, during the initial press. I'm keeping the 'b' key held down untill i release the button. So far it's working to a point with just the different release definitions but it's the switch back that's giving me probs as explained in my last post.
MFreywald
abe_beson
24-04-2005, 10:06 PM
I feel I need to get the game in order to help you out, since I do not really understand your intentions. However since UT is not my bag this will not happen...
If you post the exact sequence of button presses and releases you want, and under what conditions the sequences should happen, I could help you out perhaps. Better though is if you figure this out by yourself, since you will learn a lot and it is really fun programming these things! :)
In order to check that the fire button is released you need is something like this:
sequence
wait(NOT fireButton);
// Do anyting you need upon release of the fire button
endSequence
B.r,
Abe
MFreywald
25-04-2005, 01:46 AM
Going from my legend in the last post... the sequence is like this..
press q
hold b
release b
press n
if not shifted press e
seems so simple written out like that, but it all needs to be done with only one button press. (two if you count the shift). I'll continue trying using your script as a framework cause it's very close to what I need. So far my problem has been getting the e sent. So basicly it needs to send the e if pressed unshifted, but supress the e if the shift is pressed and then send the e after the shift is released. Thank you very much for the code. It's a big help!
MFreywald
abe_beson
25-04-2005, 11:16 AM
Hi MFreywald!
A couple of things are not clear to me yet. What should happen if you press the translocator key twice while holding the shift key? In this version of the script the entire fire sequence is allowed to run any number of times while the shift is held. Does it really make sence to send q every time this happens? Anyway here it is as good as I could make it with the info I had:
// CMS Script File
//
// Â* Â* Game Title:
// Â* Â* Written By:
// Â* Â* Â* Â* Â* Date:
//
%define translocator Â* Â* Â* Â* Â* Â* Â* Â*b1
%define inTranslocatorSequence Â* Â* Â*b2
%define inStartTranslocatorSequence Â* b3
%define inEndTranslocatorSequence Â* b3
%define translocatorKey Â* Â* Â* js1.b1
%define shiftKey Â* Â* Â* Â* Â* Â* Â*js1.b3
%define switchTranslocatorOut Â* cms.b1
%define FireTranslocatorOut Â* Â* cms.b2
%define altFireTranslocatorOut Â*cms.b3
%define switchToPrevWeaponOut Â* cms.b4
script
Â*sequence
Â* Â*wait(translocatorKey
Â* Â* Â*&& NOT inStartTranslocatorSequence
Â* Â* Â*&& NOT inEndTranslocatorSequence); // Waits until the key is pressed and the sequences are finished
Â* Â*inStartTranslocatorSequence=true;
Â* Â*inTranslocatorSequence=true;
Â* Â*// Push the switch to translocator key
Â* Â*switchTranslocatorOut=true;
Â* Â*delay(2);
Â* Â*FireTranslocatorOut=true; // Hold the fire button
Â* Â*delay(2);
Â* Â*switchTranslocatorOut=false;
Â* Â*delay(2);
Â* Â*while( NOT translocatorKey);
Â* Â*fireTranslocatorOut=false; Â*// Release the fire button
Â* Â*delay(2);
Â* Â*altFireTranslocatorOut=true;
Â* Â*delay(2);
Â* Â*altFireTranslocatorOut=false;
Â* Â*delay(2);
Â* Â*inStartTranslocatorSequence=false;
Â*endSequence
Â*sequence
Â* Â*wait( NOT translocatorKey && NOT shiftKey
Â* Â* Â* Â* Â*&& NOT inStartTranslocatorSequence
Â* Â* Â* Â* Â*&& inTranslocatorSequence );
Â* Â*inEndTranslocatorSequence=true;
Â* Â*switchToPrevWeaponOut=true;
Â* Â*delay(2);
Â* Â*switchToPrevWeaponOut=false;
Â* Â*delay(2);
Â* Â*inEndTranslocatorSequence=false;
Â* Â*inTranslocatorSequence=false;
Â*endSequence
endScript
As you can see this script is somewhat simpler than the previous one and therefore should be easier to modify. The risk for deadlock defintely is less in this script. Ooops I see that the comment density is very low, but I think you will manage! :D
Have Fun!
/Abe
Revvin
25-04-2005, 12:33 PM
Topic moved on original posters request
MFreywald
26-04-2005, 12:37 AM
ok. sorry about not being more clear about what happens in what conditions. It goes something like this.
Shifted sequence..
translocator button pressed:
press q
hold b
translocator released
release b
press n
translocator button pressed again still shifted
hold b
translocator released still shifted
release b
press n
shift button released
press e
unshifted...
translocator button pressed
press q
hold b
translocator button released
release b
press n
press e
so it's not necessary that the q be pressed everytime if the shift is held but it's not detrimental if it does get pressed to make it easier since it can be bundled with the b hold and release through the button definitions using the KEYS command like this..
pressed: KEYS +q +b -q (or KEYS +q -q +B)
release: KEYS -b
once switched to the translocator (q) it stays untill the e key is pressed. I'll import your newer script and try it out.
MFreywald
MFreywald
26-04-2005, 01:02 AM
IT WORKS!! :w00t: :yahoo:
Without even having to modify anything except the buttons. It worked perfectly!! Thank you very much for your time and effort on this. :cheers:
MFreywald
ruggbutt
26-04-2005, 01:12 AM
Another satisfied customer! :cheers:
abe_beson
27-04-2005, 10:46 PM
Ahh, the sweet taste of victory! :)
abe_beson
29-04-2005, 11:18 AM
Hi!
I reply to your PM here MFreywald, since if anyone else has followed this thread it would be interesting to him as well. I start by quoting your PM:
Hey, I was just looking at the script again cause I was gonna add another button function not related to the translocator wajaheebie.
I can follow it and understand it....but what caught my eye was the fact that InStartTranslocatorSequence and InEndTranslocatorSequence both used the same bit variable...B3. I'm just wondering how that figures into it all. I'm sure there's a real logical reason, it's just escaping me at the momment. Regardless the script works beautifully...exactly what I wanted. Thank you again. :)
[/b]
Well... if it works don't mend it! But this is definitely a bug, should be different bit variables. Use b4 for the inEndTranslocatorSequence, and hope that it doesn't crash because of the change! ;)
Actually there is a logical explanation to why this works. Since the first and second sequence are mutual exclusive (wich of course is the purpose of the inStartSequence and inEndSequence variables) there is really need for only one variable. But that doesn't mean it is a good habit to have two names for the same variable, so I still consider that a bug. So another way to fix the bug would be to rename one of the two defines reffering to b3 and remove the other. Make sure to follow through the name change thoughout the script. Everything that uses the two b3 defines should be changed to use the new name. :idea:
The bugs are there for just one reason. Crush them!!! :evil:
/Abe
MFreywald
30-04-2005, 01:53 AM
Ah, ok.. I'll go through and change them so as to not confuse myself later if have to read through it again.
Here's a new problem I'm having now. Can you maybe explain why this doesn't work?
script
Â*Â*Â*Â*timer ( ondelay, D3, 5) = JS1.B15;
Â*Â*Â*Â*if ( JS1.B15 && D3 ) then
Â*sequence
Â*while ( D3 );
Â*Â*Â*Â*Â*CMS.B7 = true;
Â*endsequence
Â*CMS.B7 = false;
Â*Â*Â*Â*else
Â*if ( JS1.B15 && NOT D3 ) then
Â*Â*Â*Â*Â*sequence
Â* Â*wait ( Not D3 );
Â* Â*Â*Â*Â*Â*CMS.B8 = true;
Â* Â*Â*Â*Â*Â*delay(1);
Â* Â*Â*Â*Â*Â*CMS.B8 = false;
Â* Â*Â*Â*Â*Â*delay(3);
Â* Â*Â*Â*Â*Â*CMS.B8 = true;
Â* Â*Â*Â*Â*Â*delay(1);
Â* Â*Â*Â*Â*Â*CMS.B8 = false;
Â*Â*Â*Â*Â*endsequence
Â*endif
Â*Â*Â*Â*endif
endscript
basicly what it's supposed to do is..
if B15 is pressed check if it's been held down for at least 5 cycles, if it has hold down CMS.B7 untill B15 is released, otherwise press CMS.B8 twice with a 3 cycle pause between presses.
as it is now, it doesn't send anything regardless of how long it's held down.
MFreywald
Bob Church
30-04-2005, 07:57 AM
Hi MFreywald,
The problem with the script is kind of obscure, but basically it will end up in the "ELSE" part of the conditional as soon as js1.b15 closes and it can never advance through the loop because the first "WAIT" needs to see a TRUE then a FALSE to proceed. It comes in FALSE originally and it never sees a TRUE->FALSE transition. It would really need to see a FALSE->TRUE->FALSE sequence and that won't ever happens, so it just hangs there until you release the button.
Try this, I think it does what you're looking for:
script
// Logic to hold cms.b7 if js1.b15 is held longer
// than 5 ticks.
//
timer( ONDELAY, d1, 5 ) = js1.b15;
cms.b7 = js1.b15 AND d1;
// Logic to generate the double pulse if it's not on
// for 5 ticks.
//
timer( PERIOD, d2, 5 ) = js1.b15;
timer( OFFDELAY, d3, 9 ) = d2 AND NOT js1.b15;
timer( INTERVAL, d4, 3, 3 ) = d3;
cms.b8 = d4;
endScript
The OFFDELAY lets the INTERVAL timer run long enough for ont 3-tick TRUE, one 3-tick FALSE, and a second 3-tick TRUE once it's started, so if you need to play with the timing be sure to adjust those periods. The OFFDELAY timer fires when the js1.b15 opens before the PERIOD timer runs out. The ONDELAY is just used to generate the continuous pulse if js1.b15 is held long enough to skip the double pulse operation.
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
MFreywald
30-04-2005, 08:53 AM
Awesome, that works perfect Bob thanks! :cheers:
MFreywald
Bob Church
30-04-2005, 11:58 AM
Hi MFreywald,
>> Awesome, that works perfect Bob thanks! <<
You're welcome! I'm glad it did the trick!
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
vBulletin® v3.7.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.