Jump to content

Texture Change Script Syntax Error


Reymundo
 Share

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

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

Recommended Posts

Okay so I have been working on a script for texture changing and while I have it setup with 3 scripts I'm trying to put them all into 1 script for less lag. But I keep getting a syntax error and I'm not sure why. I'm not the best with scripting so forgive me. Anyway this is what I have:

 

////////////////////////////////////////////////////////////////////
////////////////// [ MESH WORKSHOP SCRIPTS ]///////////////////////
//////////////////////////////////////////////////////////////////

integer ch=-13577; //Same unique 5 digit number as controller.
integer ch1=-13578; //Same unique 5 digit number as controller.
integer ch2=-13579; //Same unique 5 digit number as controller.

integer side = 5; //Side to apply the texture to.
// ALL_SIDES = All sides of the object.
// Numbers 1-8 = Face number of the object.

integer side2 = 6; //Side to apply the texture to.
// ALL_SIDES = All sides of the object.
// Numbers 1-8 = Face number of the object.

integer side3 = 3; //Side to apply the texture to.
// ALL_SIDES = All sides of the object.
// Numbers 1-8 = Face number of the object.

integer side4 = 2; //Side to apply the texture to.
// ALL_SIDES = All sides of the object.
// Numbers 1-8 = Face number of the object.

//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////

 

 


default
{
state_entry()
{
llListen(ch,"",NULL_KEY,"");
}

listen(integer ch, string name, key id, string msg)
{
if (llGetOwner() == llGetOwnerKey(id))
{
llSetTexture(llGetSubString(msg,0,-1),side);
llSetColor(<0.5, 0.0, 0.0>, side );
llSetTexture(llGetSubString(msg,0,-1),side2);
llSetColor(<0.5, 0.0, 0.0>, side2 );
}
}
}

{
llListen(ch1,"",NULL_KEY,"");
}

listen(integer ch1, string name, key id, string msg)
{
if (llGetOwner() == llGetOwnerKey(id))
{
llSetTexture(llGetSubString(msg,0,-1),side3);
llSetColor(<0.5, 0.0, 0.0>, side3 );
}
}
}

Link to comment
Share on other sites

Not sure if it will work but it compiles.

The first listener is never removed so (I think) it's still active.

integer ch=-13577; //Same unique 5 digit number as controller.
integer ch1=-13578; //Same unique 5 digit number as controller.
integer ch2=-13579; //Same unique 5 digit number as controller.
integer side = 5; //Side to apply the texture to.
// ALL_SIDES = All sides of the object.
// Numbers 1-8 = Face number of the object.

integer side2 = 6; //Side to apply the texture to.
// ALL_SIDES = All sides of the object.
// Numbers 1-8 = Face number of the object.

integer side3 = 3; //Side to apply the texture to.
// ALL_SIDES = All sides of the object.
// Numbers 1-8 = Face number of the object.

integer side4 = 2; //Side to apply the texture to.
// ALL_SIDES = All sides of the object.
// Numbers 1-8 = Face number of the object.
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////



default
{
state_entry()
{
llListen(ch,"",NULL_KEY,"");
}
listen(integer ch, string name, key id, string msg)
{
if (llGetOwner() == llGetOwnerKey(id));
{
llSetTexture(llGetSubString(msg,0,-1),side);
llSetColor(<0.5, 0.0, 0.0>, side );
llSetTexture(llGetSubString(msg,0,-1),side2);
llSetColor(<0.5, 0.0, 0.0>, side2 );
}

llListen(ch1,"",NULL_KEY,"");
{
if (llGetOwner() == llGetOwnerKey(id));
llSetTexture(llGetSubString(msg,0,-1),side3);
llSetColor(<0.5, 0.0, 0.0>, side3 );
}
}
}

 

Link to comment
Share on other sites

It compiles, but won't work the way you expect.

This part ...

{ 
if (llGetOwner() == llGetOwnerKey(id));
llSetTexture(llGetSubString(msg,0,-1),side3);
llSetColor(<0.5, 0.0, 0.0>, side3 );
}

doesn't make any sense as written.  The if test ends with a semi-colon, which will be interpreted as an empty statement and ignored. (Take a look at this recent thread >>> https://community.secondlife.com/t5/LSL-Scripting/So-are-my-math-skills-wrong-or-did-LSL-forget-how-to-do-math/td-p/3056502 ) And the curly brackets define a scope that has no purpose.  Try instead

if (llGetOwner() == llGetOwnerKey(id))
{
llSetTexture(llGetSubString(msg,0,-1),side3);
llSetColor(<0.5, 0.0, 0.0>, side3 );
}

 

Link to comment
Share on other sites

Hmm...so it compiles it all now but nothing happens. I also wanted to know why side and side2 apply one after the other instead of at the same time. Here's what I have.

 

////////////////////////////////////////////////////////////////////////////////////// [ MESH WORKSHOP SCRIPTS ]/////////////////////////////////////////////////////////////////////////////////////////      integer ch=-13577;          //Same unique 5 digit number as controller.integer ch1=-13578;          //Same unique 5 digit number as controller.integer ch2=-13579;          //Same unique 5 digit number as controller.integer side = 5;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.                            integer side2 = 6;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.                            integer side3 = 3;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.                            integer side4 = 2;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////default{    state_entry()    {        llListen(ch,"",NULL_KEY,"");    }    listen(integer ch, string name, key id, string msg)    {          if (llGetOwner() == llGetOwnerKey(id))       {            llSetTexture(llGetSubString(msg,0,-1),side);           llSetColor(<0.5, 0.0, 0.0>, side );           llSetTexture(llGetSubString(msg,0,-1),side2);           llSetColor(<0.5, 0.0, 0.0>, side2 );       }        llListen(ch1,"",NULL_KEY,"");    {          if (llGetOwner() == llGetOwnerKey(id))           llSetTexture(llGetSubString(msg,0,-1),side3);           llSetColor(<0.5, 0.0, 0.0>, side3 );       }               llListen(ch2,"",NULL_KEY,"");    {          if (llGetOwner() == llGetOwnerKey(id))           llSetTexture(llGetSubString(msg,0,-1),side4);           llSetColor(<0.5, 0.0, 0.0>, side4 );       }    }}
Link to comment
Share on other sites


Reymundo wrote:

I also wanted to know why side and side2 apply one after the other instead of at the same time.

Many appearance functions (excluding llSetLinkPrimitiveParamsFast) have a delay of 0.2s. This delay between lines is causing what you're seeing.

In this case the delay is being caused by llSetTexture.

Secondly, the correct way to write an if statement is as follows:-

if(test){    doStuff();}

Inside an event and stacked, this should look like:-

event(key id){    if(test)    {        doStuff();    }    else    {        doOtherStuff();    }    if(test2)    {         doAlternateStuff();    }

doStuffRegardlessOfTest();}

  • Like 1
Link to comment
Share on other sites

Okay so I need to change the other two if statements to else...or something? Sorry it's kinda confusing, and is there not a way to make it apply to side and side 2 at the same time? Those two faces are part of one area of the prim is why I ask.

Link to comment
Share on other sites


Reymundo wrote:

is there not a way to make it apply to side and side 2 at the same time? Those two faces are part of one area of the prim is why I ask.

The only constant that affects multiple sides is ALL_SIDES. If this isn't appropriate then there will be some delay simply because you'll need two separate commands, how much depends on the function you use. Again, llSetLinkPrimitiveParamsFast has no intrinsic delay and will allow you to staple commands together.

E.g. (from the Wiki):-

llSetLinkPrimitiveParamsFast(LINK_SET, [                PRIM_FULLBRIGHT, ALL_SIDES, FALSE,                PRIM_LINK_TARGET, llDetectedLinkNumber(0),                PRIM_FULLBRIGHT, ALL_SIDES, TRUE]);/*This executes:       //Fullbright FALSE       //Link_target to root       //Fullbright TRUE as a single function call.*/

Reymundo wrote:

Okay so I need to change the other two if statements to else...or something?

I clarified style because I don't really understand what your script is supposed to process at present. Procedurally it does the following:-

listen(...){     if(speaker is Avatar)     {          setTexture/Color     }    beginListen for Ch1    if(speaker is Avatar)    {          setTexture/Color    }    //etc...}

All it'll do is create a lot of listeners and result TRUE for every if inside the listen event. This doesn't appear useful or intentional.

  • You probably want to initialise all the listeners in state_entry (if you need this many)
  • You probably then want to if-test against channel to test which listener is triggering the listen event.

E.g.:-

listen(...){    if(llGetOwnerKey(id) == id)    {        if(channel == ch1)        {             DoListen1Stuff();        }       else if(channel == ch2)       {            DoListen2Stuff();       }    }}        

But this is a guess because I'm not sure what the code you've written is supposed to accomplish.

Link to comment
Share on other sites

Well the original script, is designed to texture a prim, in this case an outfit by using a HUD to shift through different textures. I added to this enabling it to change the texture followed by coloring the texture (because I was trying to avoid just using loads of textures when the same result can ber achieved via coloring one) and while I got my end result it involved using 3 scripts in one prim. I'm simply trying to streamline that and make it less laggy. So the exampling you gave doesn't really help me fix the problem.

Should also mention the original script applied to either all faces or one face, but I am trying to texture different faces of an outfit different textures/colors.

Link to comment
Share on other sites

I'm also confused about what the script is intended to do. It seems that the listen handler only does things if the message received is from the prim's owner. If that's the desired effect, there is no need for those if() tests inside the listen handler. The call to llListen() should contain the owner's key, not the null key. Then only messages originating from the prim's owner will trigger the listen handler, a much more efficient way to do things.

I also can't remember if calling llListen() with a channel that's already got a registered listen closes the previous listener or not. If it doesn't, that script is going to rapidly fill up the listen queue (65 max) and then fail, as there are no llListenRemove() calls. If the goal is to receive messages from three different objects (hence the three channels) all owned by the owner of the receiving object, the script should open three listen handlers at the start, one for each channel, all keyed to the owner.

default{    state_entry()    {        key owner = llGetOwner();        llListen(ch0,"",owner,"");        llListen(ch1,"",owner,"");        llListen(ch2,"",owner,"");    }    listen(integer ch, string name, key id, string msg)    {          if(ch==ch0)       {           do stuff to side, side2       }      else if(ch==ch1)      {            do stuff to side3       }             else if(ch==ch2)    {          do stuff to side4    }}

 

Link to comment
Share on other sites

So doing it the way you showed should make it do what it's intended purpose is? As I said I took the original script and modified it to suit the changes I was needing so I don't know why the original script used the if and null parts. Just know it worked as separate scripts, but I will try it the way you've shown and see if it works.

Link to comment
Share on other sites


Reymundo wrote:

So doing it the way you showed should make it do what it's intended purpose is? As I said I took the original script and modified it to suit the changes I was needing so I don't know why the original script used the if and null parts. Just know it worked as separate scripts, but I will try it the way you've shown and see if it works.

We don't know the intended purpose, so there's no way we can say if the things we've recommended will work.

Link to comment
Share on other sites

Okay so I did what you said and well, syntax error lol.

 

////////////////////////////////////////////////////////////////////////////////////// [ MESH WORKSHOP SCRIPTS ]/////////////////////////////////////////////////////////////////////////////////////////      integer ch0=-13577;          //Same unique 5 digit number as controller.integer ch1=-13578;          //Same unique 5 digit number as controller.integer ch2=-13579;          //Same unique 5 digit number as controller.integer side = 5;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.                            integer side2 = 6;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.                            integer side3 = 3;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.                            integer side4 = 2;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////default{    state_entry()    {        key owner = llGetOwner();        llListen(ch0,"",owner,"");        llListen(ch1,"",owner,"");        llListen(ch2,"",owner,"");    }    listen(integer ch, string name, key id, string msg)    {          if(ch==ch0)       {            llSetTexture(llGetSubString(msg,0,-1),side);           llSetColor(<0.5, 0.0, 0.0>, side );           llSetTexture(llGetSubString(msg,0,-1),side2);           llSetColor(<0.5, 0.0, 0.0>, side2       }      else if(ch==ch1)      {              llSetTexture(llGetSubString(msg,0,-1),side3);           llSetColor(<0.5, 0.0, 0.0>, side3 );       }             else if(ch==ch2)    {              llSetTexture(llGetSubString(msg,0,-1),side4);           llSetColor(<0.5, 0.0, 0.0>, side4 );    }}
Link to comment
Share on other sites

Of course:

         llSetColor(<0.5, 0.0, 0.0>, side2

Always check your work for typos (missing brackets, parentheses, semi-colons, etc.)  It can help to use a decent script editor instead of relying on the one in your viewer, which has lousy (i.e. non-existent) error messages.

Link to comment
Share on other sites

Okay so it compiled finally...but it's still not applying the texture and color...

 

////////////////////////////////////////////////////////////////////////////////////// [ MESH WORKSHOP SCRIPTS ]/////////////////////////////////////////////////////////////////////////////////////////      integer ch0=-13577;          //Same unique 5 digit number as controller.integer ch1=-13578;          //Same unique 5 digit number as controller.integer ch2=-13579;          //Same unique 5 digit number as controller.integer side = 5;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.                            integer side2 = 6;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.                            integer side3 = 3;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.                            integer side4 = 2;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////default{    state_entry()    {        key owner = llGetOwner();        llListen(ch0,"",owner,"");        llListen(ch1,"",owner,"");        llListen(ch2,"",owner,"");    }    listen(integer ch, string name, key id, string msg)    {          if(ch==ch0)       {            llSetTexture(llGetSubString(msg,0,-1),side);           llSetColor(<0.5, 0.0, 0.0>, side );           llSetTexture(llGetSubString(msg,0,-1),side2);           llSetColor(<0.5, 0.0, 0.0>, side2 );       }      else if(ch==ch1)      {              llSetTexture(llGetSubString(msg,0,-1),side3);           llSetColor(<0.5, 0.0, 0.0>, side3 );       }             else if(ch==ch2)      {              llSetTexture(llGetSubString(msg,0,-1),side4);           llSetColor(<0.5, 0.0, 0.0>, side4 );       }    }}
Link to comment
Share on other sites

that's because it's only listening for the owner to speak, not objects. assuming you're using a hud with prim buttons, you'll need to leave the listen open, and then test if the speaking object is owned by the same owner

I made the edits below in red to show you what I added

 


Reymundo wrote:

Okay so it compiled finally...but it's still not applying the texture and color...

 
////////////////////////////////////////////////////////////////////////////////////// [ MESH WORKSHOP SCRIPTS ]/////////////////////////////////////////////////////////////////////////////////////////      integer ch0=-13577;          //Same unique 5 digit number as controller.integer ch1=-13578;          //Same unique 5 digit number as controller.integer ch2=-13579;          //Same unique 5 digit number as controller.integer side = 5;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.                            integer side2 = 6;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.                            integer side3 = 3;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.                            integer side4 = 2;   //Side to apply the texture to.                            // ALL_SIDES = All sides of the object.                            // Numbers 1-8 = Face number of the object.//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////default{    state_entry()    {                llListen(ch0,"",,"");        llListen(ch1,"",,"");        llListen(ch2,"",,"");    }    listen(integer ch, string name, key id, string msg)    {

if(ch==ch0) { llSetTexture(llGetSubString(msg,0,-1),side); llSetColor(<0.5, 0.0, 0.0>, side ); llSetTexture(llGetSubString(msg,0,-1),side2); llSetColor(<0.5, 0.0, 0.0>, side2 ); } else if(ch==ch1) { llSetTexture(llGetSubString(msg,0,-1),side3); llSetColor(<0.5, 0.0, 0.0>, side3 ); } else if(ch==ch2) { llSetTexture(llGetSubString(msg,0,-1),side4); llSetColor(<0.5, 0.0, 0.0>, side4 ); } }
}

 

Link to comment
Share on other sites

How is it communicating the textures to the script? If it's saying the name of the texture, it would need to be in the object's inventory with this script. If it's saying the texture uuid, it should work. Are you getting any errors shouted? Try putting an llOwnerSay(msg); in the listen event to see what it's actually receiving. Also llGetSubString(msg,0,-1) is a little redundant as it's telling it to use the whole message anyways

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2802 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...