Difference between revisions of "Button Click Detector"
Jump to navigation
Jump to search
m (Minor language change for ToS compliance.) |
Lady Sumoku (talk | contribs) m (Replaced old <LSL> block with <source lang="lsl2">) |
||
(2 intermediate revisions by 2 users 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 12: | Line 12: | ||
default | default | ||
{ | { | ||
touch_start(integer total_number) | touch_start(integer total_number) | ||
{ | { | ||
Line 40: | Line 35: | ||
if( idx > llGetListLength(buttons) ) { | if( idx > llGetListLength(buttons) ) { | ||
llSay(0, "Great, you stumped me. | llSay(0, "Great, you stumped me. Push off."); | ||
return; | return; | ||
} | } | ||
Line 49: | Line 44: | ||
} | } | ||
} | } | ||
</ | </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.");
}
}