Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Texture cycler with press & hold trigger - select individual textures

Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
04-05-2007 14:26
This is an outgrowth of my press & hold trigger code.

How this works is, you load up a prm with textures and the script. The prim will automatically display the first texture (as expected) and each mouse click will rotate to the next one.

Where this is different is, if you hold down the mouse key for two seconds, you get a dialog asking if you want to take the texture. This can be handy if you are on a building project and want to keep a hot list of textures handy in your "Recent Items" tab without having a lot of unwanted textures in inventory (which can slow you down by contributing to inventory lag and also by having to constantly search for the exact texture...). With a little more code jiggery, someone could also add a pay method allowing buyers to purchase individual textures instead of having to buy (or choose not to buy) complete sets.

CODE

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

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

// used for texture cycling
integer count;
integer i;
string texture_name;

// used to retrieve texture
key agent_key;

display(integer n)
{
llSetTexture(texture_name, ALL_SIDES);
llSetText(llGetObjectName() + "\n" + (string)(n+1) + " of " + (string)count + " - " + texture_name, <1.0,1.0,1.0>, 1.0);
}
get_texture()
{
llGiveInventory(agent_key, texture_name);
}
B()
{
llSay(0, "B Pressed");
}
touch_hold()
{
elapsed = llGetAndResetTime();
llListenControl(listenHandle, TRUE); // ...enable
llSetTimerEvent(idle_time);
llDialog(llDetectedKey(0), texture_name, menu, myChannel);
}
default
{
state_entry()
{
listenHandle = llListen(myChannel,"","","");
elapsed = 0.0;
count = llGetInventoryNumber(INVENTORY_TEXTURE);
i = 0;
texture_name = llGetInventoryName(INVENTORY_TEXTURE, 0);
display(i);
}
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) {
agent_key = llDetectedKey(0);
touch_hold();
}
}
}
touch_end(integer num_detected)
{
if (elapsed < trigger_time) {
i += 1;
if (i >= count) i = 0;
texture_name = llGetInventoryName(INVENTORY_TEXTURE, i);
display(i);
}
}
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) == "GET TEXTURE") {
get_texture();
}
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
04-09-2007 04:59
/15/69/175647/1.html
_____________________
i've got nothing. ;)
Dragger Lok
(loading ...)
Join date: 10 Sep 2006
Posts: 228
So So Very Close-
07-22-2007 17:11
A forward and back button would make this everyones dream come true- makes me want to learn scripting not hacking.... still an amazing script!