Difference between revisions of "Button Click Detector"
Jump to navigation
Jump to search
Kireji Haiku (talk | contribs) m (some minor readability improvements) |
Lady Sumoku (talk | contribs) m (Replaced old <LSL> block with <source lang="lsl2">) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
< | <source lang="lsl2"> | ||
// This script assumes a grid of 4 columns, 3 rows of buttons as listed in the 'buttons' list below. | // This script assumes a grid of 4 columns, 3 rows of buttons as listed in the 'buttons' list below. | ||
// But you can change it as you like, just change horizontal to the # of columns and vertical to the # of rows, | // But you can change it as you like, just change horizontal to the # of columns and vertical to the # of rows, | ||
Line 7: | Line 7: | ||
integer horizontal = 4; | integer horizontal = 4; | ||
integer vertical = 3; | integer vertical = 3; | ||
list buttons = [ "brown", "red", "orange", "yellow", | |||
list buttons = [ | "blue", "cyan", "lblue", "gray", | ||
"green", "puke", "purple", "pink" ]; | |||
default | default | ||
{ | { | ||
touch_start(integer total_number) | |||
touch_start(integer | |||
{ | { | ||
vector | vector v = llDetectedTouchUV(0); | ||
if( | if( v == TOUCH_INVALID_TEXCOORD ) { | ||
llSay(0, "I don't know what you just did."); | |||
llSay( | |||
return; | return; | ||
} | } | ||
float x = v.x; | |||
float y = 1.0-v.y; | |||
integer rowno = (integer)( | |||
integer idx; | |||
integer rowno; | |||
integer colno; | |||
rowno = (integer)(y / (1.0/(float)vertical)); | |||
colno = (integer)(x / (1.0/(float)horizontal)); | |||
idx = rowno*horizontal + colno; | |||
if( llGetListLength(buttons) | if( idx > llGetListLength(buttons) ) { | ||
llSay(0, "Great, you stumped me. Push off."); | |||
llSay( | |||
return; | return; | ||
} | } | ||
llSay( | llSay(0, "Click at " + (string)x + ", " + (string)y); | ||
llSay( | llSay(0, "That is, row " + (string)rowno + ", col " + (string)colno); | ||
llSay( | llSay(0, "That is, you clicked near the " + llList2String(buttons,idx) + " button."); | ||
} | } | ||
} | } | ||
</ | </source> |
Latest revision as of 00:10, 22 January 2015
// This script assumes a grid of 4 columns, 3 rows of buttons as listed in the 'buttons' list below.
// But you can change it as you like, just change horizontal to the # of columns and vertical to the # of rows,
// and of course the buttons list must be updated as well. Other than that the code (and more importantly, the MATH)
// should not need updating.
integer horizontal = 4;
integer vertical = 3;
list buttons = [ "brown", "red", "orange", "yellow",
"blue", "cyan", "lblue", "gray",
"green", "puke", "purple", "pink" ];
default
{
touch_start(integer total_number)
{
vector v = llDetectedTouchUV(0);
if( v == TOUCH_INVALID_TEXCOORD ) {
llSay(0, "I don't know what you just did.");
return;
}
float x = v.x;
float y = 1.0-v.y;
integer idx;
integer rowno;
integer colno;
rowno = (integer)(y / (1.0/(float)vertical));
colno = (integer)(x / (1.0/(float)horizontal));
idx = rowno*horizontal + colno;
if( idx > llGetListLength(buttons) ) {
llSay(0, "Great, you stumped me. Push off.");
return;
}
llSay(0, "Click at " + (string)x + ", " + (string)y);
llSay(0, "That is, row " + (string)rowno + ", col " + (string)colno);
llSay(0, "That is, you clicked near the " + llList2String(buttons,idx) + " button.");
}
}