Jump to content

Control Events question


Innula Zenovka
 Share

You are about to reply to a thread that has been inactive for 4117 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I'm a bit confused with control events.   What I've got, having studied the article in the LSL wiki, is 

 

 integer up_left = CONTROL_ROT_LEFT|CONTROL_FWD;


if((held & change) && (change & up_left)){
			llOwnerSay("up left");
		}

 I was expecting it to say "up left" only if I've pressed both the left and up arrow keys, but instead it's firing if I press either.

What I want it do to is say "left" or "up", as appropriate, if I press one, and then "up left" if I press both.   Where am I going wrong, please?

Link to comment
Share on other sites

it might help you to know how controls report...

keydown = held:true, change:true
keyheld = held:true, change:false
keyup = held:false, change:true

each key is a single bit in the control event, the bits positions match across the held and change variables. using bitwise AND (&) compares if particular bits (keys) are set to true or false. using logical AND (&&) checks if ANY bits are set.

Link to comment
Share on other sites

A bit of binary maths...

integer up_left = CONTROL_ROT_LEFT|CONTROL_FWD;if ((held & change & up_left) == up_left){    llOwnerSay("up left");}

Or more verbosely:

if (((held & up_left) == up_left) && ((change & up_left) == up_left))

That will do the trick.

 

Link to comment
Share on other sites

that's a good solution, but be aware that it will trigger only when just those two keys are held down, or when those keys are held down and third key is released.

Kalura's will only triger if those two keys are held down at the same time (and controls trigger fast so it must be in the same frame)

if you don't want them to be exclusive, and want to catch asynchronous presses
((change & up_left) && ((held & up_left) == up_left))
will be be more forgiving (at least one of the two changed, and both are now down)

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4117 days.

Please take a moment to consider if this thread is worth bumping.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...