Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Blink Script

Anya Yalin
AnnaMayaHouse
Join date: 27 May 2008
Posts: 150
11-12-2009 13:13
Hello everyone. I'm not sure if I can really ask for specific help on here, but I'm having some trouble with an open source blink script I found.

I need a blink script for a pet I made, which has two eyes on two separate prims. I've used a blink script for another project before, but that worked by loading the eyes open/eyes closed textures every time, and you could see the reload every so often, which I found annoying.

So I decided to try texture animation. My problem with that was that I wanted 4 frames max, to keep my texture quality good. If I just ran through the texture, of course either the eye would blink constantly or it would stay closed for a long time, because of the limited number of frames.

Then I found the following open source blink script that I'm pasting below. For some reason, and I'm not sure why, it makes the eye stay open longer despite the limited frames in my texture. This script was designed for avatars though and has all kinds of avatar related features that I don't need. It detects if you're afk among other things. I'm wondering if anyone knows how to 'clean up' this script, take out everything avatar related that I don't need. With all the stuff in the script right now I don't know what exactly is causing the texture animation to be what it is. (And I'd like to tweak it.)

(I'd also be very grateful if someone could tell me how to link the two eyes. I have absolutely no scripting knowledge. I know I'm asking a lot, but people are always friendly on here so I thought I'd try :) )


// Blinke Script Open Source
// Redesigned Blink Script (DG) to incorporate manual eye opening
// Author: Zombie Pye

// This script is open source! Distribute the basic version of this at your leisure. Usable in avatars intended for sale. You may remove the permissions for modified versions of this script. Do not resell the script itself in any form!

// The first line within the listen event causes the object to respond to other objects owned by the same owner. This makes this script HUD compatible: just have it say the eye open/close command on touch. By default, it listens to channel 50.

// Note the eyes also close when AFK or Busy. The commands are (case sensitive): "eyes open", "eyes rest", "eyes squint", "eyes close"

integer blink = TRUE;
integer eyes;
integer length;

default
{
on_rez(integer sparam)
{
llResetScript();
}

listen(integer ch, string name, key id, string msg)
{
if(llGetOwnerKey(id) == llGetOwner())
{
if(msg == "eyes open";)
{
eyes = 0;
length = 0;
blink = TRUE;
}

if(msg == "eyes rest";)
{
eyes = 1;
length = 3;
blink = TRUE;
}

if(msg == "eyes squint";)
{
eyes = 2;
length = 2;
blink = TRUE;
}

if(msg == "eyes close";)
{
blink = FALSE;
llSetTextureAnim(ANIM_ON, ALL_SIDES, 2, 2, eyes, length, 12);
}
}
}

state_entry()
{
llListen(50,"", "", "";);
llSetTimerEvent(.1);
}

timer()
{
integer info = llGetAgentInfo(llGetOwner());
if(info & AGENT_AWAY)
{
blink = FALSE;
llSetTextureAnim(ANIM_ON, ALL_SIDES, 2, 2, eyes, length, 12);
state noblink;
}

if(blink)
{
{
llSetTextureAnim(ANIM_ON, ALL_SIDES, 2, 2, eyes, length, 12);
llSetTextureAnim(ANIM_ON | REVERSE, ALL_SIDES, 2, 2, eyes, length, 12);
llSetTimerEvent(5 + llFrand(5));
}
}
}
}

state noblink
{
state_entry()
{
llSetTimerEvent(.5);
}

timer()
{
integer agentinfo = llGetAgentInfo(llGetOwner());
if(~agentinfo & AGENT_AWAY)
{
llSetTextureAnim(ANIM_ON | REVERSE, ALL_SIDES, 2, 2, eyes, length, 12);
blink = TRUE;
state default;
}
}
}
_____________________
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
11-13-2009 03:11
Bah... It's not complicate. Here are 2 scripts. Put one in each eye.

(Quote me to retrieve the layout.)

//==========================================
list Commands = ["open", "rest", "squint", "close"];
integer Previous = FALSE;

default
{
state_entry()
{
llListen(50,"", "", "";); // Remove this line to disable chat commands
llSetTimerEvent(0.1);
}

// Remove all this to disable chat commands >>>>>
listen(integer channel, string name, key id, string msg)
{
if (llGetOwnerKey(id) != llGetOwner()) { return; }
list tempo = llParseString2List(llToLower(msg), [" "], []);
if (llList2String(tempo, 0) != "eyes";) { return; }
integer k = llListFindList(Commands, llList2String(tempo, 1));
if (k == 0)
{
llMessageLinked(LINK_SET, -2220555, "1, 0, 0", "";); // "eyes open"
}
else if (k == 1)
{
llMessageLinked(LINK_SET, -2220555, "1, 1, 3", "";); // "eyes rest"
}
else if (k == 2)
{
llMessageLinked(LINK_SET, -2220555, "1, 2, 2", "";); // "eyes squint"
}
else if (k == 3)
{
llMessageLinked(LINK_SET, -2220555, "0, 0, 0", "";); // "eyes close"
}
}
// <<<<< all this

timer()
{
llSetTimerEvent(0.0);
llMessageLinked(LINK_SET, -2220555, "1, 0, 0", "";);
}

link_message(integer sender, integer code, string msg, key id)
{
if (code != -2220555) { return; }
list tempo = llCSV2List(msg);
blink = llList2Integer(tempo, 0);
eyes = llList2Integer(tempo, 1);
length = llList2Integer(tempo, 2);
if (blink)
{
llSetTextureAnim(ANIM_ON, ALL_SIDES, 2, 2, eyes, length, 12);
llSetTextureAnim(ANIM_ON | REVERSE, ALL_SIDES, 2, 2, eyes, length, 12);
Previous = TRUE;
llSetTimerEvent(5.0 + llFrand(5.0));
}
else if (blink != Previous)
{
llSetTextureAnim(ANIM_ON, ALL_SIDES, 2, 2, eyes, length, 12);
Previous = FALSE;
}
}
}
//==========================================
//
// The end
//

The second script:

//==========================================
integer Previous = FALSE;

default
{
link_message(integer sender, integer code, string msg, key id)
{
if (code != -2220555) { return; }
list tempo = llCSV2List(msg);
blink = llList2Integer(tempo, 0);
eyes = llList2Integer(tempo, 1);
length = llList2Integer(tempo, 2);
if (blink)
{
llSetTextureAnim(ANIM_ON, ALL_SIDES, 2, 2, eyes, length, 12);
llSetTextureAnim(ANIM_ON | REVERSE, ALL_SIDES, 2, 2, eyes, length, 12);
Previous = TRUE;
llSetTimerEvent(5 + llFrand(5));
}
else if (blink != Previous)
{
llSetTextureAnim(ANIM_ON, ALL_SIDES, 2, 2, eyes, length, 12);
Previous = FALSE;
}
}
}
//==========================================

I kept the chat commands so you can make your pet sleep or have expressions. However, if it was my project, I would use just the linked messages sent from the root prim, for example.
Anya Yalin
AnnaMayaHouse
Join date: 27 May 2008
Posts: 150
11-13-2009 04:24
Heya Kaluura :)
Thanks so much for your reply already.

I'm getting an error though when saving the scripts, "name not defined within scope" on the line "blink = llList2Integer(tempo, 0);" in both scripts.

I'm a bit confused too. Which script goes in the root and which in each eye? (Sorry, no scripting experience whatsoever. I only understand part of the scripts.)
_____________________
Anya Yalin
AnnaMayaHouse
Join date: 27 May 2008
Posts: 150
11-13-2009 07:42
Ok, I got rid of that error by changing the first part of the scripts to this:

integer Previous = FALSE;
integer blink;
integer eyes;
integer length;

default


No idea if that's the right way of doing it though :D
When that error's gone I still get an error in the first script, "function call mismatches type or number of arguments" on this line:

integer k = llListFindList(Commands, llList2String(tempo, 1));


(That one's not a big deal actually, it's in the chat command part that I'll probably remove anyway.)

I tried just putting script 1 in one eye, script 2 in the other, which is what I think I should be doing now that I reread your comment. (I always thought something needed to be in the root to link stuff.)

They blink at a good pace and don't bork in no script regions (just stop blinking) which is good. Occasionally they're not totally in sync though, so dunno if maybe I'm still doing something wrong.
_____________________
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
Shortest version.
11-13-2009 09:04
I think this works just as well.

CODE


default
{
on_rez(integer sparam)
{
llSetTimerEvent(.1);
}

timer()
{
llSetTextureAnim(ANIM_ON, ALL_SIDES, 2, 2, 0, 0, 12);
llSetTextureAnim(ANIM_ON | REVERSE, ALL_SIDES, 2, 2, 0, 0, 12);
llSetTimerEvent(5 + llFrand(5));
}
}

Anya Yalin
AnnaMayaHouse
Join date: 27 May 2008
Posts: 150
11-13-2009 09:29
Thanks Ron :o
I tried something similar to that before, because I could tell that was the part actually controlling the texture animation, but I didn't get it completely right I think.

How do I go about linking the eyes then though?

Kaluura's script seems to work fine now too. The eyes only seem to go out of sync in this Openspace sim I know, which might just be an Openspace issue :s
_____________________
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
Linking.
11-13-2009 12:38
You can link the eyes to the rest of the thing to make it one linkset.
Then to make them blink in sync, you can use linkmessages.

One way of doing this is to put this script in one eye:

CODE


default
{
on_rez(integer sparam)
{
llSetTimerEvent(.1);
}

timer()
{
llMessageLinked(LINK_SET, 1, "Blink", "");
llSetTimerEvent(5 + llFrand(5));
}

link_message(integer sender_number, integer number, string message, key id)
{
if (number && message == "Blink"){
llSetTextureAnim(ANIM_ON, ALL_SIDES, 2, 2, 0, 0, 12);
llSetTextureAnim(ANIM_ON | REVERSE, ALL_SIDES, 2, 2, 0, 0, 12);
}
}
}



And this one in the other:

CODE


default
{
link_message(integer sender_number, integer number, string message, key id)
{
if (number && message == "Blink"){
llSetTextureAnim(ANIM_ON, ALL_SIDES, 2, 2, 0, 0, 12);
llSetTextureAnim(ANIM_ON | REVERSE, ALL_SIDES, 2, 2, 0, 0, 12);
}
}
}



Or you can put the timer part of the first script in a script in the rootprim and the second script in both the eyes.
Anya Yalin
AnnaMayaHouse
Join date: 27 May 2008
Posts: 150
11-13-2009 13:02
Thanks so much, Ron :)

Both yours and Kaluura's scripts work fine, but I might switch to these because they're a bit faster maybe. Interestingly enough the eyes go out of sync in Openspace sims with these scripts too. I didn't know Openspace could have such an effect on scripting. (The eyes don't go out of sync on regular sims.)
_____________________
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
11-13-2009 13:37
I'm guessing it's more a matter of the texture lagging a little. The linkmessages should trigger in both eyes simultaneous.
Anya Yalin
AnnaMayaHouse
Join date: 27 May 2008
Posts: 150
11-13-2009 16:07
Ah could be. It does sometimes take a blink or two for them to sync entirely, but in that Openspace sim it does seem to take a long time. And even if they've blinked in sync a couple of times, they still go out of it occasionally.

Thanks again for the help :)
_____________________