Jump to content

Problem with a combined script


Miguelito Shilova
 Share

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

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

Recommended Posts

I've got an issue that I suspect the solution is so simple, that my inexperienced mind just isn't seeing it - I hope someone can spot the problem(s) - thanks in advance for your help.

What I am doing is combining two scripts to create a whitelist controlled cover. I have a 'tub' that is comprised of four mesh components (including the cover with this script included in it) and two standard prims. One prim is invisible and serves as the root prim. Aside from the cover, all the other prims (including the other standard prim that serves as 'water') are set to physics none - the cover, although a mesh, is set to physics prim. Here is what it looks like with the cover rolled up. The cover is the dark line on the backside top edge (NOTE: the cover is not the root prim).

Screen Shot 2014-09-11 at 7.47.27 PM.png

And here is what it looks like with the cover 'extended'

Screen Shot 2014-09-11 at 7.48.34 PM.png

The intent is to use the cover to control access to the tub. I'm using Zilla Larson's rollup blind script to facilitate the rollup effect when touched. By itself it works just fine as you can see from the two images above. Here is the standalone blind script:

 

//When touched the prim is retracted towards one end and when touched again stretched back out.
//
//Prim moves/changes size along the local coordinate specified in the offset vector below.
//
//To change the overall size, edit the prim when stretched out and reset the script when done.
//
//The script works both in unlinked and linked prims.
//
// Copyright (C) 2008 Zilla Larsson
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 3, as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>


vector offset = <1,0,0>; //Prim moves/changes size along this local coordinate
float hi_end_fixed = FALSE; //Which end of the prim should remain in place when size changes?
//The one with the higher (local) coordinate?
float min = 0.05; //The minimum size of the prim relative to its maximum size
integer ns = 10; //Number of distinct steps for move/size change


default {
state_entry() {
offset *= ((1.0 - min) / ns) * (offset * llGetScale());
hi_end_fixed -= 0.5;
}

touch_start(integer detected) {
integer i;
do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset,
PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]);
while ((++i) < ns);
offset = - offset;
}
}

 

I'm attempting to use this script as the 'event' in Rolig Loon's Whitelist script. Here is the script where I have combined the above with the whitelist script:

// Generic Whitelist Script -- Rolig Loon -- March 2011

// Put login names (NOT Display names) of avatars to be whitelisted in a notecard, one per line
// Spelling and capitalization count

list gWhiteList = [];
string gCard;
integer gLine;
key gQuery;
list gWho = ["Me Only","Group","List","Group+List","Everyone"];
integer gAccess;
integer gDChnl;

// declarations for the opening and closing cover ...

vector offset = <1,0,0>; //Prim moves/changes size along this local coordinate
float hi_end_fixed = FALSE; //Which end of the prim should remain in place when size changes?
//The one with the higher (local) coordinate?
float min = 0.05; //The minimum size of the prim relative to its maximum size
integer ns = 10; //Number of distinct steps for move/size change

default // Read Whitelist from notecard, one name per line
{
state_entry()
{
if(llGetInventoryNumber(INVENTORY_NOTECARD) == 1)
{
gCard = llGetInventoryName(INVENTORY_NOTECARD,0);
gQuery = llGetNotecardLine(gCard, 0);
}
else
{
llOwnerSay("The whitelist notecard is missing.");
}
}

changed(integer change)
{
if (change & CHANGED_INVENTORY)
{
llResetScript();
}
}

dataserver(key QID, string data)
{
if(gQuery == QID)
{
if (data != EOF)
{
gWhiteList += [llStringTrim(data,STRING_TRIM)];
gQuery = llGetNotecardLine(gCard, ++gLine);
}
else
{
llOwnerSay("Initialized");
state running;
}
}
}
}

state running
{
state_entry()
{
gDChnl = (integer) ("0xF" + llGetSubString(llGetOwner(),0,6));
}

changed(integer change)
{
if (change & CHANGED_INVENTORY)
{
llResetScript();
}
}

touch_start(integer total_number)
{
llResetTime();
integer idx = llListFindList(gWhiteList,[llDetectedName(0)]);
if (llDetectedKey(0) != llGetOwner())
{
if ((gAccess == 4) ||
((gAccess == 3) && (~idx || llSameGroup(llDetectedKey(0)))) ||
((gAccess == 2) && (~idx)) ||
((gAccess == 1) && (llSameGroup(llDetectedKey(0)))))
{
llSay(0,"Access granted.");
state OK;
}
else
{
llSay(0,"Access denied.");
}
}
}

touch_end(integer num) //Mouse button released
{
if(llDetectedKey(0) == llGetOwner())
{
if (llGetTime() < 3.0 ) //Less than 3 seconds after mouse button down
{
llSay(0,"Access granted.");
state OK;
}
else if (llGetTime() >= 3.0 ) // Owner set access permissions
{
llListen(gDChnl,"","","");
llDialog(llGetOwner(),"Who should have access?",gWho,gDChnl);
}
}
}

listen(integer channel, string name, key id, string msg)
{
gAccess = llListFindList(gWho,[msg]);
string temp;
if (gAccess == 0)
{
temp = "you only.";
}
else if (gAccess == 1)
{
temp = "group members only.";
}
else if (gAccess == 2)
{
temp = " \n" + llDumpList2String(gWhiteList," \n");
}
else if (gAccess == 3)
{
temp = "this group and " + " \n" +llDumpList2String(gWhiteList, " \n");
}
else
{
temp = "everyone.";
}
llOwnerSay("Access has been granted to " + temp);
}
}

state OK
{
state_entry()
{
llSetTimerEvent(10.0);
llSay(0,"You're in!");
}

changed(integer change)
{
if (change & CHANGED_INVENTORY)
{
llResetScript();
}
}

touch_start(integer detected) {
integer i;
do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset,
PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]);
while ((++i) < ns);
offset = - offset;
}

timer() // Return to previous state if nothing else happens before timer triggers
{
llSetTimerEvent(0.0);
state running;
}
}

 

I have the notecard in the cover prim as well, and it only has my login name at the moment. When initialized and clicked the script authorizes me, and then with a second click the cover begins to move. Here is where the problems show up ...

Upon the second click to open, both sides of the cover extract (not just one) so the cover rolls up to the center (and appears to be thinner than when the cover does not have the combined script:

Screen Shot 2014-09-11 at 7.51.07 PM.png

When clicked again to close, the tub sprouts wings :)

Screen Shot 2014-09-11 at 7.51.31 PM.png

Again, I am hoping the solution is simple, and would really appreciate some guidance as to what the problem might be.

Thanks!

--Mig

 

Link to comment
Share on other sites

<facepalm> "oy vey" </facepalm> :) You're right, it is. I've applied it to 'state OK' ...

 

state OK{    state_entry()    {         llSetTimerEvent(10.0);        llSay(0,"You're in!");        offset *= ((1.0 - min) / ns) * (offset * llGetScale());        hi_end_fixed -= 0.5;    }    changed(integer change)    {        if (change & CHANGED_INVENTORY)        {            llResetScript();        }    }       touch_start(integer detected) {        integer i;        do  llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset,                PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]);        while ((++i) < ns);                   offset = - offset;    }           timer()  // Return to previous state if nothing else happens before timer triggers.                 //I think we need to enter some events here that set values check the current position and size of the cover and reverse the motion and size    {        llSetTimerEvent(0.0);        state running;     }}

That made some progress. What I am seeing now is that on the second click (after the whitelist is checked against my login name), the cover will correctly move to the open position, and then to the close position when clicked again. But when I click it again after a certain period of time, regardless if it's in the open or closed state, the cover 'barely' moves - you just see just a little bit of shifting. I also noticed when the process repeats again, no discernable movement is shown.

I suspect the problem is that my variables are not retaining workable values for the calculation after the timer expires and the script is returned to the running state. I just don't know how to solve for that. I'm hoping this is a common problem, and my post here will help provide additional resources for others looking to solve something similar. I certainly appreciate any help I can get. 

Thanks again!

--Mig

Link to comment
Share on other sites

Thanks! I will try these changes this evening.

The shift-copy doesn't concern me too much, but what about the notecard edits? Can I avoid that by ensuring the notecard is only edited when the cover in the stretched position? If so, is there a path I could take with the code that ensures this, like maybe a call in the default state_entry using Llsetlinkprimitiveparamsfast and defining its size?

Link to comment
Share on other sites

Indeed you could hardcode it's size and position as global variables.

To print out the size, and pos in chat.
llOwnerSay("vector gvSize = " + llList2String(llGetLinkPrimitiveParams(LINK_THIS, [PRIM_SIZE]), 0) +";");llOwnerSay("vector gvPos = " + llList2String(llGetLinkPrimitiveParams(LINK_THIS, [PRIM_POS_LOCAL]), 0) + ";");

To set the size and pos in default state at the very first in state_entry.
llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_SIZE, gvSize, PRIM_POS_LOCAL, gvPos]);

 

Link to comment
Share on other sites

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