Jump to content

Terrible at scripting, would love some help!


Dodger Elan
 Share

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

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

Recommended Posts

So, I'm terrible at scripting and this has been driving me crazy. I'm really hoping someone might be able to help me out. Basically, I made a mesh head and it blinks using a randomised script which switches the alpha between two versions of the head (eyes open, eyes closed). However, each head also has eyelashes which are linked to it, and I can't figure out how to have the eyelashes disappear/appear with their corresponding head.

Hopefully that makes sense, basically I want to achieve this: https://www.youtube.com/watch?v=IxihuX6KJeU

This is the script:

 

float randomized_time = 7.0; 
float animation_speed = 0.5;
integer total_prims;
integer link_counter;

action()
{ llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES); llSetLinkAlpha( link_counter,1.0, ALL_SIDES);
}

default
{ state_entry() { total_prims = llGetNumberOfPrims(); state warmup; }
}

state warmup
{ state_entry() { state trigger; } changed( integer c) { if ( c & CHANGED_LINK) { llResetScript(); } }
}


state trigger
{ state_entry() { llSetTimerEvent(animation_speed); } timer() { link_counter++; action(); if( link_counter == total_prims) { link_counter = 0; state wait; } }
}

state wait
{ state_entry() { llSetTimerEvent(llFrand(randomized_time)­); } changed( integer c) { if ( c & CHANGED_LINK) { llResetScript(); } } timer() { state warmup; }
}

Any help would be greatly appreciated!!! 

Link to comment
Share on other sites

Are you saying that there are two linksets, each consisting of a face and eyelashes, or that you have the faces and their eyelashes all linked together into one linkset? The former will involve chatting to convey instructions between seperate linksets. The latter is the way to go.

What you need to do is name each componet of the link set like this

face 1

eyelashes 1

face 2

eyelashes 2

You then use a loop in the setup to find the link number for each of those named components, and when you hide face 1, you also hide eyalashes 1, showing instead face 2 and eyelashes 2.

 

integer face1 = -1;integer eyelashes1 = -1;integer face2 = -1;integer eyelashes2 = -1;integer faceToShow;setup(){    integer iiMax = llGetNumberOfPrims();    integer ii;    for( ii = 1; ii <= iiMax; ++ii)    {        string name = llGetLinkName(ii);        if( name == "face 1") face1 = ii;        // repeat for all other parts    }}showFace( integer which){    if( which == 1)    {        llSetLinkAlpha( face2, 0.0, ALL_SIDES);        llSetLinkAlpha( eyelashes2, 0.0, ALL_SIDES);        llSetLinkAlpha( face1, 1.0, ALL_SIDES);        llSetLinkAlpha( eyelashes1, 1.0, ALL_SIDES);    }    // and do the opposite if which == 2}

Not tested in world or sytnax checked.

 

Have a look at another thread in this forum where a sliding door problem was discussed, the technique in question was touiched on there. https://community.secondlife.com/t5/LSL-Scripting/Multi-door-Sliding-Door-Script/td-p/2952434

  • Like 1
Link to comment
Share on other sites

Oh, okay - no worries. Sorry about that!

I've tried to get this to work but it keeps coming up with a syntax error. Is there anything you (or anyone else) can see that's off? D:

 

integer face1 = -1;integer eyelashes1 = -1;integer face2 = -1;integer eyelashes2 = -1;integer faceToShow;setup(){    integer iiMax = llGetNumberOfPrims();    integer ii;    for( ii = 1; ii <= iiMax; ++ii)    {        string name = llGetLinkName(ii);        if( name == "face1") face1 = ii;        string name = llGetLinkName(ii);        if( name == "eyelashes1") eyelashes1 = ii;                       string name = llGetLinkName(ii);        if( name == "face2") face2 = ii;                string name = llGetLinkName(ii);        if( name == "eyelashes2") eyelashes2 = ii;    }}showFace( integer which){    if( which == 1)    {        llSetLinkAlpha( face2, 0.0, ALL_SIDES);        llSetLinkAlpha( eyelashes2, 0.0, ALL_SIDES);        llSetLinkAlpha( face1, 1.0, ALL_SIDES);        llSetLinkAlpha( eyelashes1, 1.0, ALL_SIDES);    }    if( which == 2)    {        llSetLinkAlpha( face2, 1.0, ALL_SIDES);        llSetLinkAlpha( eyelashes2, 1.0, ALL_SIDES);        llSetLinkAlpha( face1, 0.0, ALL_SIDES);        llSetLinkAlpha( eyelashes1, 0.0, ALL_SIDES);    }    }
Link to comment
Share on other sites

Well, yes, if that's the whole script, it lacks the default state :)

What I posted for you was not a full solution but some snippets for guidance, based on your initial script which showed that you do know about states, and event handlers inside the states. The setup routine is to be called once at startup (and after any changed_link event), and the other routine would be called from different states when one face was to be switched for another.

You are close, anyway. Inside the setup routine, you only need to get the value for name once, then after the first if ... test,

you put an else if test for the second possible part, another for the third, and so on

You add in the default state, and make a call to Setup(). Then you set a global variable to 1 or 2, depending on which of the two faces you want to show, and you call the function to switch faces with this global variable as the argument. Inside a touch event, you toggle the global variable between 2 and 1, and again call the function to switch faces with that variable value as the argument. You don't actually need any other state than the default. The global, by the way, is a;ready there in the snippet called faceTpShow, so inside the touch event, you would have showFace(faceToShow); after changing the value of faceToShow from 2 to 1 or vice-versa.

I suggest you look at the other thread I linked to in the first reply, and go through it to the point where I replied, because the snippet I posted there is showing the way to call an initialisation routine in better detail (though with dfewer parts, but that's just leg-work).

Link to comment
Share on other sites

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