PDA

View Full Version : Gamma increase/decrease



RoyHatch
4th November 2008, 12:39 AM
Why doesn't this work?





// CMS Script File
//
//
script

//Gamma... CMS BUTTONS HAVE GAMMA COMMANDS THAT INCREASE OR
// DECREASE GAMMA DEPENDING ON THE VALUE OF A1. CMS 13 AND 12
// INCREASE GAMMA AND 11 AND 10 DECREASE



SEQUENCE

if (JS1.B12 ) then
A1 = A1 + 1 ;
else

if ( JS1.B10 ) then
A1 = A1 - 1 ;
endif
endif

ENDSEQUENCE

SELECT( A1, POSITION ) OF

CASE 0:
CMS.B13 = TRUE; // Set the bit for our first message
EXITCASE:
CMS.B13 = FALSE; // Clear the bit for our first message
BREAK;

CASE 1:
CMS.B12 = TRUE; // Set the bit for our second message
EXITCASE:
CMS.B12 = FALSE; // Clear the bit for our first message
BREAK;

CASE 2:
CMS.B11 = TRUE; // Set the bit for our third message
EXITCASE:
CMS.B11 = FALSE; // Clear the bit for our third message

BREAK;

CASE 3:
CMS.B10 = TRUE; // Set the bit for our fourth message
EXITCASE:
CMS.B10 = FALSE; // Clear the bit for our fourth message
BREAK;

ENDSELECT



endScript

Bob Church
4th November 2008, 04:56 AM
Hi Roy,

I don't know whether it's the whole problem, but the first part of the script isn't going to play well:


SEQUENCE
if (JS1.B12 ) then
A1 = A1 + 1 ;
else
if ( JS1.B10 ) then
A1 = A1 - 1 ;
endif
endif
ENDSEQUENCE

As soon as you click js1.b0 or js1.b12, it's going to start incrementing/decrementing A1 and it can move 3 counts in as little as 30 ms. It's going to wind A1 out of your case range at the top or bottom just about instantly. There's no limit set on the value A1 can attain short of it being a 32-bit integer, so probably as fast as you can push the button it's well out of range of the 0..3 case statement and on it's way to +/- 2^^31 or so. It can get a long way out of range in a hurry. The SEQUENCE statements wouldn't have effect there. You need to use WAIT or WHILE for it to be any help.

You could try something like:


sequence
wait( js1.b10 );
if([ a1 < 3 ]) then
a1 = a1 + 1;
endIf
endSequence
sequence
wait( js1.b12 );
if([ a1 > 0 )] then
a1 = a1 - 1;
endIf
endSequence

That would just increment or decrement once on each click and keep in thehe click, and it would keep it in the case range. I didn't try it, seems like it ought to work. CMS zeroes things when you start the script, so it should start at 0 but there's a FIRSTSCAN flag that will be true on the first pass through the script. You can "IF" on that and initialize things if you need to and it will only run once, the first scan after it leaves Direct Mode and enters Mapped Mode.

Best regards,

- Bob

The StickWorks
http://www.stickworks.com

RoyHatch
4th November 2008, 09:44 PM
that worked.... thanks