Jump to content

Help: Texture parameters read from notecard


AdminGirl
 Share

You are about to reply to a thread that has been inactive for 1436 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi

I've been trying to incorporate bits into a texture change script (from wiki) so that I can set the parameters of the texture application via a notecard, but after adding the notecard bits into the script, the texture doesn't apply at all.

The lines in my notecard are:

gFace: ALL_SIDES
gRepeats:<1.0,1.0,1.0>
gOffsets:<1.0,1.0,1.0>
gRotationInDegrees: 0.0

 

Anyone able to point out which part I got wrong please? Thanks so much.

string notecardName;
integer notecardLine;

key query;

list MENU1 = [];
list MENU2 = [];
integer listener;
integer MENU_CHANNEL = 1000;

integer gFace;
vector  gRepeats;
vector  gOffsets;
float   gRotationInDegrees;
 
Dialog(key id, list menu)
{
    llListenRemove(listener);
    listener = llListen(MENU_CHANNEL, "", NULL_KEY, "");
    llDialog(id, "Select texture below: ", menu, MENU_CHANNEL);
}


default
{
    state_entry()
    {
        notecardLine = 0;
        notecardName = llGetInventoryName(INVENTORY_NOTECARD,0);
        if (notecardName != "")
        {
            llOwnerSay("Getting configuration data...");
            query = llGetNotecardLine(notecardName,notecardLine);
        }
        else
        {
            llOwnerSay("There is no notecard in object's inventory, please add a config notecard.");
        }
    }
 
    changed(integer change)
    {
        if (change & CHANGED_INVENTORY) // If notecard changes script is resetted.
        {
            llOwnerSay("Resetting script");
            llResetScript();
        }
    }
 
    on_rez(integer number)
    {
        llResetScript();
    }
 
    touch_start(integer total_number)
    {
        llSay(0, "Touched: "+(string)total_number);
    }
 
    dataserver(key requested, string data)
    {
        if (requested == query)
        {
            if (data != EOF)
            {
                //ignore lines that start with # and blank lines
                if ( (llGetSubString(data,0,0) != "#") && (data != "") )
                {
                    list tempData = llParseString2List(data,[":"],[]);
                    string command = llToLower(llList2String(tempData,0));
 
                    if (command == "gFace")
                    {
                        gFace = llList2Integer(tempData,1);
                        llOwnerSay(command + ": " + (string)gFace);
                    }
                    else if (command == "gRepeats")
                    {
                        gRepeats = (vector)llList2String(tempData,1); // This converts a string to a vector 
 
                        // Set up the vector properly//
                        gRepeats.x = gRepeats.x;
                        gRepeats.y = gRepeats.y;
                        gRepeats.z = gRepeats.z;
                        llOwnerSay(command + ": " + (string)gRepeats);
                    }
                    else if (command == "gOffsets")
                    {
                        gOffsets = (vector)llList2String(tempData,1); // This converts a string to a vector 
 
                        // Set up the vector properly//
                        gOffsets.x = gOffsets.x;
                        gOffsets.y = gOffsets.y;
                        gOffsets.z = gOffsets.z;
                        llOwnerSay(command + ": " + (string)gOffsets);
                    }
                    else if (command == "gRotationInDegrees")
                    {
                        gRotationInDegrees = llList2Float(tempData,1);
                        llOwnerSay(command + ": " + (string)gRotationInDegrees);
                    }
                }
                notecardLine++;
                query = llGetNotecardLine(notecardName,notecardLine);
            }
            else
            {
                //End of notecard reached, we go to the ready state.
                state ready;
            }
        }
    }
}
 
state ready
{
    on_rez(integer num)
    {
        // reset scripts on rez
        llResetScript();
    }
 
    touch_start(integer total_number)
    {
        integer i = 0;
        MENU1 = [];
        MENU2 = [];
        // count the textures in the prim to see if we need pages
        integer c = llGetInventoryNumber(INVENTORY_TEXTURE);
        if (c <= 12)
        {
            for (; i < c; ++i)
                MENU1 += llGetInventoryName(INVENTORY_TEXTURE, i);
        }
        else
        {        
            for (; i < 11; ++i)
                MENU1 += llGetInventoryName(INVENTORY_TEXTURE, i);
            if(c > 22)
                c = 22;
            for (; i < c; ++i)
                MENU2 += llGetInventoryName(INVENTORY_TEXTURE, i); 
            MENU1 += ">>";
            MENU2 += "<<";                          
        }
        // display the dialog 
        Dialog(llDetectedKey(0), MENU1);
    }
 
    listen(integer channel, string name, key id, string message) 
    {
        if (channel == MENU_CHANNEL)
        {
            llListenRemove(listener);  
            if (message == ">>")
            {
                Dialog(id, MENU2);
            }
            else if (message == "<<")
            {
                Dialog(id, MENU1);
            }        
            else                    
            {
                // display the texture from menu selection 
                llSetPrimitiveParams([PRIM_TEXTURE,
                                    gFace,
                                    message,
                                    gRepeats,
                                    gOffsets,
                                    gRotationInDegrees*DEG_TO_RAD]
                                    );
 
            }      
        }
    }

    timer()
    {
        llListenRemove(listener);
        llSetTimerEvent(0.0);
    } 
}

 

Link to comment
Share on other sites

The first thing I spotted was that in the notecard you have the text "ALL_SIDES". Only the compiler sees that as a constant with the value -1.

So you can either replace "ALL_SIDES" in the notecard with "-1", or you can read it as a string and then, in the script, test that string for "ALL_SIDES", in which case assign -1 (or the constant ALL_SIDES) to the face number, or if the string isn't that, cast the string to an integer and assign that to the face number.

The next thing I spotted is that you extract a lowercase version of the command you read from the notecard, but then you test that against strings that include an uppercase character, as in "gFace", so the condition will never be true.

So either don't use llToLower when you extract the command from the notecard, or, having converted it to lowercase, compare it against a lowercase version of the command.

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

Also, regardless of what the variables on your notecard look like to you, as a human, the script will read them all as string variables. Sometimes you can get away with expecting a script to do implicit typecasting, but I rarely trust it.  I suggest always typecasting variables explicitly. So, for example,

gFace = (integer)llList2String(tempData,1);

instead of 

gFace = llList2Integer(tempData,1);

I will often go farther than that if I am writing a script that will be used by someone else, because I know that most SL residents don't know the difference between a vector and a rotation, for example.  Even those who know what a UUID looks like may mistype one by putting a "-" in the wrong place. I will therefore build in a quick check to verify that the value that the script reads is actually a valid vector, rotation, or key. 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 4 weeks later...

Hi :) 

Adding something minor... 

gRepeat = <1.0, 1.0, 1.0>; // <x, y, z> : x is the horizontal repeat, y 1.0 is the vertical repeat, z remains unused. So I usually type <1.0, 1.0, 0.0> to remind me that this is for repeats and not for the color of white.

gOffsets = <1.0, 1.0, 1.0>; // I would rather type <0.0, 0.0, 0.0>. <1.0, 1.0, 1.0> (or <1.0, 1.0, 0.0>, respectively, since z remains unused), shifts the whole texture completely all the way horizontally und vertically, the result is then the same as <0.0, 0.0, 0.0> which does not shift the texture at all. Too many texture shifts may result in undesired results in laggy areas.

I strongly recommend Rolig Loon's suggestion to always use llList2String() and typecast it to integer, float, vector... whatever is needed. Stupid me suffered too long from believing you can rely on that other llList2....() work. No. No-no.

  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1436 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...