Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Press & Hold trigger emulation

Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
04-01-2007 07:41
Function of this code is to wait until a user presses and holds down the mouse key for 2 seconds before triggering an action - in this case presenting a basic menu.

You would want to use it for those occasions where you want to administer an object (such as setting up an access list, running a configuration utility, perform window tinting, etc) with a mouse touch, but you want to filter out unintentional random clicks.

Currently the code restricts access to the objects owner (in two locations - touch_start and touch). It would make sense to encapsulate the access check to a separate function and add an additional test in the listen event as well for greater security. A 2nd expansion would add a configuration variable to switch between owner, group, and public access.

CODE

// set these to whatever values you wish
integer myChannel = 123;
float trigger_time = 2.0;
float idle_time = 10.0;
list menu = ["A", "B"];

// used for controlling command entry
float elapsed = 0.0;
integer listenHandle;

A()
{
llSay(0, "A Pressed");
}
B()
{
llSay(0, "B Pressed");
}
touch_hold()
{
elapsed = llGetAndResetTime();
llListenControl(listenHandle, TRUE); // ...enable
llSetTimerEvent(idle_time);
llDialog(llDetectedKey(0), "Menu Stub", menu, myChannel);
}
default
{
state_entry()
{
listenHandle = llListen(myChannel,"","","");
elapsed = 0.0;
}
on_rez(integer startup_param)
{
llResetScript();
}
touch_start(integer num_detected)
{
if (llDetectedKey(0) == llGetOwner()) {
elapsed = llGetAndResetTime();
}
}
touch(integer num_detected)
{
if (llDetectedKey(0) == llGetOwner()) {
elapsed = llGetTime();
if (elapsed > trigger_time) {
touch_hold();
}
}
}
timer()
{
llSetTimerEvent(0.0);
llListenControl(listenHandle, FALSE); // ...disable
}
listen(integer chan, string name, key id, string cmd)
{
if (llListFindList(menu, [cmd]) != -1) {
if (llToUpper(cmd) == "A") {
A();
}
else if (llToUpper(cmd) == "B") {
B();
}
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
04-09-2007 04:58
/54/f0/176342/1.html
_____________________
i've got nothing. ;)