Jump to content

Trying and failing at writing script. Need help...please


Kristy McBride
 Share

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

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

Recommended Posts

I'm not a scripter but have been trying to figure out how to write a script for my greeting cards. I have two mesh cards, a closed version and an open version. What I want to do is have the closed version, when touched, disappear and the open version show in it's place. I would really appreciat some help. Thanks!

Link to comment
Share on other sites

That's actually pretty easy.  You don't need to write a script that opens and closes the card.  All you need is one that switches transparency ( llSetLinkAlpha ) from 0.0 to 1.0 on one version of the card as it switches the other way on the other version.  So, take a look at http://wiki.secondlife.com/wiki/LlSetLinkAlpha to see how that function works.  Your linked object (two versions of the card) has two links (1 and 2).

Here's a very simple toggle switch:

 

integer gON;default{    touch_start(integer num)    {        gON = !gON;        if (gON)        {            //Do "on" stuff        }        else        {            // Do "off" stuff        }    }}

Now all you have to do is put the pieces together.

Link to comment
Share on other sites

Link the two cards together, then name each individually "open card" and "closed card".

 

integer openCard = -1;integer closedCard = -1;integer openClosed = -1;getCards(){    integer ii;    integer iiMax = llGetNumberOfPrims();    for( ii = 1; ii <= iiMax; ++ii)    {        string sName = llGetLinkName(ii);        if( sName == "open card") openCard = ii;        else if( sName == "closed card") closedCard = ii;    }    if( openCard == -1 || closedCard == -1) llWhisper(0, "Check my names!");    else    {        llSetLinkAlpha(openCard, 0.0, ALL_SIDES);        llSetLinkAlpha(closedCard, 1.0, ALL_SIDES);        openClosed = 0;    }}default{    state_entry()    {        getCards();    }    touch_start( integer touches)    {        if( openClosed == 0)        {            llSetLinkAlpha(closedCard, 0.0, ALL_SIDES);            llSetLinkAlpha(openCard, 1.0, ALL_SIDES);            openClosed = 1;        }    }}

Not checked inworld, be prepared to de-typo it

 

ETA sighs, Rolig, you did it to me again :)

Link to comment
Share on other sites

We do not write complete scripts for people here.  That's not the purpose of this forum.  The LSL Scripting forum is a place for scripters to trade ideas and headaches.  If you have experimented with a script you are writing and want to ask a specific question, like you just did, we'll do our best to point you in the right direction so you can learn to do it yourself.

So...... If you looked at the toggle switch that I offered earlier, you may have discovered that it does just that --- switches from ON to OFF, however you have defined what ON and OFF are.  So, if you put the pieces together carefully, you should be able to make link 1 and link 2 swap visibility.  Now, if you look at the function llSetLinkAlpha, which I also refered you to, you'll see that you can specify exactly which face (or faces) on either link are supposed to be switched too.  Give it a try.

Link to comment
Share on other sites

Have a look at how the variable openClosed is used. Initially it starts off at -1 and is only set to 0 when both parts of the linkset have been identified.

 

if 0 when touched, the alphas are switched over, and openClosed then set to 1.

 

Therefore you need to add an else if clause to test if it is set to 1, and iff so, to change the link alphas again, and then set the value to 0. You will be repeating the three statements that occur within the "else" block of the function that checks for the names and sets the book to closed if all the parts have been found.

It is important to note that you cannot just stick an  else... test after the test for 0 in the touch event, becuase if the variable has been left at -1 because of mis-named parts, no action should happen when touched.

(Alternatively, of course, in the touch event you could just reset the script if the variable is set to 1 when touched.)

Link to comment
Share on other sites

There is a bit more to developing a script from a snippet or simple example than looking through the wiki at definitions. For example, the names of the linkset, and the scripts inside them, and storing versions as you try changing things. Why does this matter? Because if you just leave things set to "object" and "new script", you'll get lost when the changes you try don't do what you hoped they might.

So, first of all, give the script a proper name, such as "greetings card".
Then, drag a copy of it back to your inventory.
Then, make a change, drag a copy of it back to your inventory, test the changes, if necessary, make another change...

But there's another trap here to do with the way the inventory works which came to light last week, to do with keeping track of all the versions of the script created when different things are tried.

If, when you build, you leave the default name "object" in each prim you create, how do you know what it is when you later on look in your inventory? Ok, says my friend, it doesn't matter about the children in the linset because the linkset name is what I'll see in the inventory. That's fine, until you accidentally unlink the object when it is in a physical state, and suddenly you are using object area search to scour the sim for "object" belonging to "doh". Just like renaming the script from the default "new script" to something you can later on search for.

What my friend did with the scripts was to drag a copy of the script back to their objects folder each time they made a change, and also take-copy the object itself. They relied upon the inventory sort order by date to be able to pick the latest version of all the identically-named scripts for that object by taking the name which came at the top of the list.

Then, when they thought we had finished the build, they did a cut and past, moving all the scripts and objects from the objects folder into a sub-folder.

Then, when we discovered a bug, they went to the new folder, took the third instance of the script because they assumed it was the third-most recent, and we found it wasn't. All the identically-named scripts in their folder were showing the same date and time now in the properties field, the date and time they had been pasted into the new folder. It took them half a day of going through each script in the folder until they spotted the version we actually needed.

So, name each part of your build, name each script, and append a version number to the end of the script name, then drag the renamed script accross into your inventory. When you get totally lost in some changes which no longer seem to make sense, go back to an earlier number that did work, and start again.

Hopefully in this case, the change will be a simple oone of copying the block of statements in the initialisation function which set the card to closed down to the touch event, and adding an else if so that the touch event also works when the variable in question is 1.

Link to comment
Share on other sites

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