Button Click Detector: Difference between revisions
Jump to navigation
Jump to search
m Minor language change for ToS compliance. |
Kireji Haiku (talk | contribs) m some minor readability improvements |
||
| Line 7: | Line 7: | ||
integer horizontal = 4; | integer horizontal = 4; | ||
integer vertical = 3; | integer vertical = 3; | ||
list buttons = [ "brown", "red", "orange", "yellow", | |||
"blue", "cyan", "lblue", "gray", | list buttons = [ | ||
"green", "puke", "purple", "pink" ]; | "brown", "red", "orange", "yellow", | ||
"blue", "cyan", "lblue", "gray", | |||
"green", "puke", "purple", "pink"]; | |||
default | default | ||
| Line 15: | Line 17: | ||
state_entry() | state_entry() | ||
{ | { | ||
llSay( | // PUBLIC_CHANNEL has the integer value 0 | ||
llSay(PUBLIC_CHANNEL, "Hello, Avatar!"); | |||
} | } | ||
touch_start(integer | touch_start(integer num_detected) | ||
{ | { | ||
vector | vector touchUV = llDetectedTouchUV(0); | ||
if( | if( touchUV == TOUCH_INVALID_TEXCOORD ) | ||
llSay( | { | ||
llSay(PUBLIC_CHANNEL, "I don't know what you just did."); | |||
return; | return; | ||
} | } | ||
touchUV.y = 1.0 - touchUV.y; | |||
integer rowno = (integer)(touchUV.y / (1.0/(float)vertical)); | |||
integer colno = (integer)(touchUV.x / (1.0/(float)horizontal)); | |||
integer index = rowno*horizontal + colno; | |||
integer | |||
colno = (integer)(x / (1.0/(float)horizontal)); | |||
if( | if( llGetListLength(buttons) < index ) | ||
llSay( | { | ||
llSay(PUBLIC_CHANNEL, "Great, you stumped me. Bugger off."); | |||
return; | return; | ||
} | } | ||
llSay( | llSay(PUBLIC_CHANNEL, "Click at <" + (string)touchUV.x + ", " + (string)touchUV.y + ">"); | ||
llSay( | llSay(PUBLIC_CHANNEL, "That is row " + (string)rowno + " and col " + (string)colno); | ||
llSay( | llSay(PUBLIC_CHANNEL, "That is, you clicked near the " + llList2String(buttons, index) + " button."); | ||
} | } | ||
} | } | ||
</lsl> | </lsl> | ||
Revision as of 12:24, 7 October 2012
<lsl> // 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 {
state_entry()
{
// PUBLIC_CHANNEL has the integer value 0
llSay(PUBLIC_CHANNEL, "Hello, Avatar!");
}
touch_start(integer num_detected)
{
vector touchUV = llDetectedTouchUV(0);
if( touchUV == TOUCH_INVALID_TEXCOORD )
{
llSay(PUBLIC_CHANNEL, "I don't know what you just did.");
return;
}
touchUV.y = 1.0 - touchUV.y;
integer rowno = (integer)(touchUV.y / (1.0/(float)vertical));
integer colno = (integer)(touchUV.x / (1.0/(float)horizontal));
integer index = rowno*horizontal + colno;
if( llGetListLength(buttons) < index )
{
llSay(PUBLIC_CHANNEL, "Great, you stumped me. Bugger off.");
return;
}
llSay(PUBLIC_CHANNEL, "Click at <" + (string)touchUV.x + ", " + (string)touchUV.y + ">");
llSay(PUBLIC_CHANNEL, "That is row " + (string)rowno + " and col " + (string)colno);
llSay(PUBLIC_CHANNEL, "That is, you clicked near the " + llList2String(buttons, index) + " button.");
}
} </lsl>