Texture Changer Help Pls - SLUniverse Forums
Navigation » SLUniverse Forums > Development Discussion and Support > Scripting » Texture Changer Help Pls


Scripting Discuss scripting and programming for SL and other platforms

 
Reply
 
LinkBack Thread Tools Display Modes
Old 05-04-2009, 01:23 AM   #1 (permalink)
Kitten Fuzz
 
Lo Jacobs's Avatar
 
Join Date: Jan 2008
Location: Chicago by way of Los Angeles
Posts: 4,739
SL Join Date: May 2004
Blog Entries: 17

Awards: 1
Special Achievement in Thread Titling 
Red face Texture Changer Help Pls

Okay, this is probably a very easy fix. I got this script from here --

Winter Seale

As you can see, the texture-changer script here is able to be used only if included with the resize script provided. I don't need a resize script, but I do want a texture-changer script, one that changes the texture of certain child prims (but not all of them).

It's easy to convert, isn't it?

To be placed in the root prim:

Code:
// This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License.
// To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/
// or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
// Winter Seale 2008 - winterseale.com

string MENU_NAME = "Select a color:";
string MO_BACK = "Back";
list RETURN_MENU = [ "-", "-", MO_BACK ];
list MENU_OPTIONS = [
    // Menu Name|Texture Name/UUID
    "Gray|1a93fa41-85ce-4d64-14a0-c04db47c9d9a",
    "Greenish|3b76d89b-2d96-796b-fc33-bdacd2df8fa5",
    "Rose|6d59c124-2327-c423-6c5d-52f8989dda17"
    ];

integer LM_RESET_SECRIPTS    = 101;
integer LM_SCALE_MESSAGE     = 102;
integer LM_CAN_COLOR_CHANGE  = 103;
integer LM_SHOW_COLOR_DIALOG = 104;
integer LM_SET_COLOR         = 105;
integer LM_SHOW_MAIN_DIALOG  = 106;

integer CHANNEL = -114757314;

list options_dialog;
list options_texture;

rebuild_options() {
    integer count = llGetListLength( MENU_OPTIONS );
    integer ii;
    for ( ii = 0; ii < count ; ii ++ ) {
        list pieces = llParseString2List( llList2String(MENU_OPTIONS,ii), ["|"], [] );
        options_dialog += [ llList2String(pieces,0) ];
        options_texture += [ llList2String(pieces,1) ];
    }
}

integer listenhandler;

// Rebuild our listener and turn it off.  Should really only be done
// on owner change.
reset_listener() {
    llListenRemove(listenhandler);
    listenhandler = llListen( CHANNEL, "", llGetOwner(), "");
    llListenControl( listenhandler, FALSE );
}

show_dialog() {
    list menu = RETURN_MENU + options_dialog;
    llDialog(llGetOwner(), MENU_NAME, menu, CHANNEL);
    llSetTimerEvent(60);
    llListenControl( listenhandler, TRUE );
}

send_linked(integer command, string options ) {
    integer dest = LINK_SET;
    if ( command == LM_CAN_COLOR_CHANGE || command == LM_SHOW_MAIN_DIALOG ) {
        dest = LINK_THIS;
    }
    llMessageLinked( dest, command, options, NULL_KEY );
}


default {
    state_entry() {
        rebuild_options();
        reset_listener();
        send_linked(LM_CAN_COLOR_CHANGE,"");
    }

    changed(integer mask) {
        if ( mask & CHANGED_OWNER ) {
            reset_listener();
        }
    }

    link_message(integer sender_num, integer command, string message, key id) {
        if ( command == LM_RESET_SECRIPTS ) {
            llResetScript();
        }
        else if ( command == LM_SHOW_COLOR_DIALOG ) {
            show_dialog();
        }
    }
    
    listen( integer channel, string name, key id, string message ) {
        integer sel_index = llListFindList( options_dialog, [message] );
        if ( sel_index != -1 ) {
            send_linked( LM_SET_COLOR, llList2String(options_texture,sel_index) );
            show_dialog();
        }
        else if ( message == MO_BACK ) {
            send_linked( LM_SHOW_MAIN_DIALOG, "" );
        }
    }

    timer() {
        llListenControl( listenhandler, FALSE );
        llSetTimerEvent(0);
    }
}
To be placed in the child prim:

Code:
// This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License.
// To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/
// or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
// Winter Seale 2008 - winterseale.com

integer LM_RESET_SECRIPTS    = 101;
integer LM_SCALE_MESSAGE     = 102;
integer LM_CAN_COLOR_CHANGE  = 103;
integer LM_SHOW_COLOR_DIALOG = 104;
integer LM_SET_COLOR         = 105;

default {
    link_message(integer sender_num, integer command, string message, key id) {
        if ( command == LM_RESET_SECRIPTS ) {
            llResetScript();
        }
        else if ( command == LM_SET_COLOR ) {
            llSetTexture( message, ALL_SIDES );
        }
    }
}
Big thanks to Winter Seale, and to anyone who can help me
__________________
I AM 100% SERIOUS
Lo Jacobs is offline   Reply With Quote
Old 05-04-2009, 01:38 AM   #2 (permalink)
Kitten Fuzz
 
Lo Jacobs's Avatar
 
Join Date: Jan 2008
Location: Chicago by way of Los Angeles
Posts: 4,739
SL Join Date: May 2004
Blog Entries: 17

Awards: 1
Special Achievement in Thread Titling 
For reference -- the core resizer:

Code:
// This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License.
// To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/
// or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

// Put this script in the root prim of your item

// CUSTOMIZABLE VALUES
// change here to set the desired scale change +- from the base of 1.0
// eg. 0.2 will make the scale 0.8 or 1.2 respectively

float scale_step = 0.2;


// eSimple srl 2008 - www.esimple.it - www.virtuy.com
// Ploreho design 2008 - www.ploreho.com

// Modified by Winter Seale 2008 - winterseale.com
// -- Got rid of constant listen/remove listen code and changed to using listencontrol to turn the handle on and off
// -- Got rid of all the magic numbers.
// -- Moved repeated code to functions
// -- Changed it to handle optionally having a color change script dropped in.
// -- I also changed the formatting to match my own scripts =p  


// DO NOT CHANGE BELOW THIS LINE

integer LM_RESET_SECRIPTS = 101;
integer LM_SCALE_MESSAGE = 102;
integer LM_CAN_COLOR_CHANGE = 103;
integer LM_SHOW_COLOR_DIALOG = 104;
integer LM_SET_COLOR         = 105;
integer LM_SHOW_MAIN_DIALOG  = 106;

string DEFAULT_SCALE = "d";

integer CHANNEL = -114757313;
// popup options
string MENU_NAME = "Choose the desired option:";
string DN_SIZE = "- Size";
string DF_SIZE  = "Default";
string UP_SIZE = "+ Size";
list MENU_OPTIONS = [DN_SIZE, DF_SIZE, UP_SIZE ];
string COLOR = "Color";
string NOOP = "-";
list COLOR_OPTIONS = [ NOOP,  COLOR,  NOOP  ];

integer listenhandler;
integer have_colors;

// Rebuild our listener and turn it off.
reset_listener() {
    llListenRemove(listenhandler);
    listenhandler = llListen( CHANNEL, "", llGetOwner(), "");
    llListenControl( listenhandler, FALSE );
}

// Show change menu, optionally including color the option to change colors
// if a color change script was included.  Time out after 60 seconds.
show_dialog() {
    list options = [];
    if ( have_colors ) {
        options += COLOR_OPTIONS;
    }
    options += MENU_OPTIONS;
    llDialog(llGetOwner(), MENU_NAME, options, CHANNEL);
    llSetTimerEvent(60);
    llListenControl( listenhandler, TRUE );
}

// Send link messages, using the numeric part to control what happens and
// the string part for arguments.
// All commands except LM_SHOW_COLOR_DIALOG go to the entire linkset.  The
// dialog command only goes to the same prim as the core script.
send_linked(integer command, string options ) {
    integer dest = LINK_SET;
    if ( command == LM_SHOW_COLOR_DIALOG ) {
        dest = LINK_THIS;
    }
    llMessageLinked( dest, command, options, NULL_KEY );
}

default {
    state_entry() {
            reset_listener();
            have_colors = FALSE;
    }

    touch_end(integer total_number) {
        if (llDetectedKey(0) == llGetOwner()) {
            show_dialog();
        }
    }
    
    listen(integer channel, string name, key id, string button)  {
        if ( button == DN_SIZE) {
            send_linked( LM_SCALE_MESSAGE, (string)(1.0 - scale_step) );
            show_dialog();
        }
        else if ( button == UP_SIZE ) {
            send_linked( LM_SCALE_MESSAGE, (string)(1.0 + scale_step) );
            show_dialog();
        }
        else if ( button == DF_SIZE ) {
            send_linked( LM_SCALE_MESSAGE, DEFAULT_SCALE );
            show_dialog();
        }
        else if ( have_colors && button == COLOR) {
            llListenControl( listenhandler, FALSE );
            send_linked( LM_SHOW_COLOR_DIALOG, "" );
        }
    }
    
    // This is just here to reset things when this is sold...
    changed(integer mask) {
        if ( mask & CHANGED_OWNER ) {
            // Strictly speaking, there's no reason to reset the listener, as the llMessageLinked will 
            // result in a full script reset.  However, in case it somehow gets dropped this way the item
            // won't be inert.
            reset_listener();
            llMessageLinked(LINK_SET, LM_RESET_SECRIPTS, "", NULL_KEY);
        }
    }

    link_message(integer sender_num, integer command, string message, key id) {
        if ( command == LM_RESET_SECRIPTS ) {
            llResetScript();
        }
        else if ( command == LM_CAN_COLOR_CHANGE ) {
            have_colors = TRUE;
        }
        else if ( command == LM_SHOW_MAIN_DIALOG ) {
            show_dialog();
        }
    }

    timer() {
        llListenControl( listenhandler, FALSE );
        llSetTimerEvent(0);    
    }
Lo Jacobs is offline   Reply With Quote
Old 05-04-2009, 02:14 AM   #3 (permalink)
Kitten Fuzz
 
Lo Jacobs's Avatar
 
Join Date: Jan 2008
Location: Chicago by way of Los Angeles
Posts: 4,739
SL Join Date: May 2004
Blog Entries: 17

Awards: 1
Special Achievement in Thread Titling 
Okay, I think I've fixed it myself. If you'd like to look it over and tell me if I've got any annoying bugs (like infinite loops or something, whatever those are) please, please tell me.

Code:
// This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License.
// To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/
// or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
// Winter Seale 2008 - winterseale.com

string MENU_NAME = "Select a color:";
string MO_BACK = "Back";
list MENU_OPTIONS = [
    // Menu Name|Texture Name/UUID
    "Gray|1a93fa41-85ce-4d64-14a0-c04db47c9d9a",
    "Greenish|3b76d89b-2d96-796b-fc33-bdacd2df8fa5",
    "Rose|6d59c124-2327-c423-6c5d-52f8989dda17"
    ];

integer LM_RESET_SECRIPTS    = 101;
integer LM_SCALE_MESSAGE     = 102;
integer LM_CAN_COLOR_CHANGE  = 103;
integer LM_SHOW_COLOR_DIALOG = 104;
integer LM_SET_COLOR         = 105;
integer LM_SHOW_MAIN_DIALOG  = 106;

integer CHANNEL = -114757314;

list options_dialog;
list options_texture;

rebuild_options() {
    integer count = llGetListLength( MENU_OPTIONS );
    integer ii;
    for ( ii = 0; ii < count ; ii ++ ) {
        list pieces = llParseString2List( llList2String(MENU_OPTIONS,ii), ["|"], [] );
        options_dialog += [ llList2String(pieces,0) ];
        options_texture += [ llList2String(pieces,1) ];
    }
}

integer listenhandler;

// Rebuild our listener and turn it off.  Should really only be done
// on owner change.
reset_listener() {
    llListenRemove(listenhandler);
    listenhandler = llListen( CHANNEL, "", llGetOwner(), "");
    llListenControl( listenhandler, FALSE );
}

show_dialog() {
    list menu = options_dialog;
    llDialog(llGetOwner(), MENU_NAME, menu, CHANNEL);
    llSetTimerEvent(60);
    llListenControl( listenhandler, TRUE );
}

send_linked(integer command, string options ) {
    integer dest = LINK_SET;
    if ( command == LM_CAN_COLOR_CHANGE || command == LM_SHOW_MAIN_DIALOG ) {
        dest = LINK_THIS;
    }
    llMessageLinked( dest, command, options, NULL_KEY );
}


default {
    state_entry() {
        rebuild_options();
        reset_listener();
    }

    touch_end(integer total_number) {
        if (llDetectedKey(0) == llGetOwner()) {
            show_dialog();
        }
    }

    changed(integer mask) {
        if ( mask & CHANGED_OWNER ) {
            reset_listener();
        }
    }

    link_message(integer sender_num, integer command, string message, key id) {
        if ( command == LM_RESET_SECRIPTS ) {
            llResetScript();
        }
        else if ( command == LM_SHOW_COLOR_DIALOG ) {
            show_dialog();
        }
    }
    
    listen( integer channel, string name, key id, string message ) {
        integer sel_index = llListFindList( options_dialog, [message] );
        if ( sel_index != -1 ) {
            send_linked( LM_SET_COLOR, llList2String(options_texture,sel_index) );
            show_dialog();
        }
        else if ( message == MO_BACK ) {
            send_linked( LM_SHOW_MAIN_DIALOG, "" );
        }
    }

    timer() {
        llListenControl( listenhandler, FALSE );
        llSetTimerEvent(0);
    }
}
Lo Jacobs is offline   Reply With Quote
Old 05-05-2009, 08:09 AM   #4 (permalink)
Senior Member
 
Eata's Avatar
:confusedcat:
 
Join Date: Sep 2007
Posts: 1,271
My Mood:
Business: Breach
Most of these solutions propose a script in each prim but really if you are changing few enough that it isn't horribly inefficient you might as well be hardcoding the values and doing llSetLinkTexture.

It's more work to prepare but I do it over hundreds of prims.
Eata is offline   Reply With Quote
1 User Agreed:
Old 05-06-2009, 07:47 PM   #5 (permalink)
Kitten Fuzz
 
Lo Jacobs's Avatar
 
Join Date: Jan 2008
Location: Chicago by way of Los Angeles
Posts: 4,739
SL Join Date: May 2004
Blog Entries: 17

Awards: 1
Special Achievement in Thread Titling 
Quote:
Originally Posted by Eata View Post
Most of these solutions propose a script in each prim but really if you are changing few enough that it isn't horribly inefficient you might as well be hardcoding the values and doing llSetLinkTexture.

It's more work to prepare but I do it over hundreds of prims.
This is nearly unintelligible to me, but don't feel bad. I don't know anything about scripting, really. I can just sort of inch along veeerrrry slowly.
Lo Jacobs is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On




SEO by vBSEO