Jump to content

Using a switch ?


shaun Mosswood
 Share

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

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

Recommended Posts

Hi,

 

Have just made myself a swimming pool cover that retracts into the side of the pool using a prim stretch on touch script.  What I would really like to do is to operate the cover by using a switch on the pool side but I have a feeling if I link the two together the switch will also retract.  Im certain there's a way to do this but I just can't remember.

 

Any help much appreciated :)

Link to comment
Share on other sites

Thanks for the reply but I think that solution is a bit beyond me, im not a scriptor and I wouldnt have the faintest idea as to hoe to go about changing the script with the suggestions youve given as it looks to me as thats what i have to do :)  was thinking more along the lines of an existing script that I can use to do the job but ty anyway

 

Link to comment
Share on other sites

The touch event in your pool cover is already a switch, so an extra one is not truly necessary, although I suppose it could be nice.  If you don't feel up to either of the suggestions that Darkie made, another way to solve the problem is to drop a simple toggle switch script into an unlinked prim at poolside and have it chat the Open/Closed command to your pool cover.  Unnecessary listeners add to your sim's server load, but this one isn't going to do much, so I wouldn't worry a lot. You'd just need to retool your pool cover script by adding a listen event to it that duplicates most of what's now in its touch_start event.  The toggle switch doesn't need to be anything more complicated than this:

integer gON;default{    touch_start(integer num)    {        llSay(-9876,(string)(gON = !gON));    }}

 That will send either a "0" (for Close) or a "1" (for Open) on channel -9876 whenever you click it.  Listen for that one-character string in the pool cover script and you've got it.

 

 

 

Link to comment
Share on other sites

ok I am understanding whats being told to me here and I do get why the use of these comands is required but ....

"You'd just need to retool your pool cover script by adding a listen event to it that duplicates most of what's now in its touch_start event"

thats the problem lol a script, to me, is just a jumble of numbers and very odd comands that are totally over my head so im sorry but I would not have a clue how to "toggle" the existing script, much like asking me to learn japanese in 5 minutes - ask me to build you something and im there, scripts no chance - guess i just stick with what I have unless I can sort this out somehow :)

 

 

Link to comment
Share on other sites

you need 3 changes in your pool cover stretching script:

 

___________________________________________

 

above the red word       default      that is in your script, put this..

integer chan = -9876;

 

in the    state_entry()    add this line...

 llListen(chan,"", "","");

 

and where you see this.. touch_start(integer num)

change it to this....

 

 listen(integer chan, string name, key id, string mes)

 

_______________________________________

then, just use Rolig's script in a small prim you made for the control :)

(or you could post the pool cover script & we could change it for you?)

 

 

Link to comment
Share on other sites

The idea for this LSL Scripting forum is not to provide free scripts, but to help each other learn how to write our own scripts better.  I posted that simple switch as a starter, so you'd have a place to work from. Try your hand at modifying the pool cover script. Since you already have that script running and you have some guidance from what Xiija and I have said, you ought to have a good shot at the modifications. If you run into trouble, post it and we will help talk you through how do do it better.  You can learn Japanese.  :smileywink:

BTW, the advice Xiija gave you is incomplete.  As you make your modifications, see if you can understand why.

Link to comment
Share on other sites

We all found scripting difficult when we started, but it's not too hard once you stop telliing yourself it is.   I "knew" I couldn't script until I had an argument with someone who'd sold me a door script that didn't do what I wanted, and I thought "if an idiot like that can make scripts, even ones that don't work right, I can certanly do it better. How difficult can opening and closing a door be, anyway?".

Let's walk through a rather different way of doing it, which doesn't involve chat messages.

I don't know what " stretch on touch script" you are using, but let's assume it's something like the Curtain Script in the Wiki library, recently greatly simplified by Omei Qunhua.  

Copy that and past it into your pool cover, and play with the settings at the top until it's working how you want, on touch:

vector  ScaleLarge = <0.1, 3.0, 6.0>;vector  ScaleSmall = <0.1, 3.0, 1.2>;integer gSteps  = 20;   	// Number of steps in the shrink/expand processfloat   gSwitch = 1.0;  	// Action on first touch. +1.0 = shrink, -1.0 = expand

 

Then, when you are happy with that, find the touch_start event in the script.  That's this bit:

 

    touch_start(integer total_number)    {	vector ScaleStep = (ScaleLarge - ScaleSmall) / gSteps;  // Compute the scale augment per step	vector wscale = llGetScale();	gSwitch *= -1;   	// Switch between stretch and contract	integer i;	for (i = 0; i < gSteps; i++)	{	    // It is more lag-friendly to incorporate a sleep per step	    // Rather than greatly increasing the number of steps	    llSleep(0.1);  		    llSetScale(wscale + ScaleStep * i * gSwitch); 	}    }

 Change this to 

	link_message(integer sender_number, integer number, string message, key id)	{		if (message!="go"){ //if the message isn't "go"			return; // ignore it -- not for us		}		vector ScaleStep = (ScaleLarge - ScaleSmall) / gSteps;  // Compute the scale augment per step		vector wscale = llGetScale();		gSwitch *= -1;   	// Switch between stretch and contract		integer i;		for (i = 0; i < gSteps; i++)		{			// It is more lag-friendly to incorporate a sleep per step			// Rather than greatly increasing the number of steps			llSleep(0.1);			llSetScale(wscale + ScaleStep * i * gSwitch);		}	}

 So, what you have done is taken out the line touch_start (integer total_number), replaced it with link_message(integer sender_number, integer number, string message, key id), and added the little bit about 

if (message!="go"){ //if the message isn't "go"			return; // ignore it -- not for us		}

 at the start of that section.

This has told the script that, rather than respond to someone touching that prim, you want it to monitor link messages from other prims -- these are messages that prims in the same linkset can send each other, completely separate from the listen event -- and, if the message is "go" do the stretching and shrinking stuff it was doing before when you touched it.

Now, you need to make a script to send the message "go" to the pool cover.   This bit is easy:

default{	state_entry()	{	}	touch_start(integer total_number)	{		if (llDetectedLinkNumber(0)==llGetLinkNumber()){//only respond if someone touches this particular prim			llMessageLinked(LINK_SET,0,"go","");//send the message "go" to all the prims in the object.		}	}}

 What this doing is telling the prim only to respond if someone touches the prim the script is in (otherwise, if it's in the root prim,  the pool cover will move when any prim in the linkset is touched, which probably isn't what you want to happen).  If someone touches it, it sends the message "go" to all the prims in the linkset (the 0 and the "" are simply placeholders the function llMessageLinked contains for for numbers and uuids we might want to send as part of the message, but in this example we don't  need to use them).

Put this second script in the Switch prim.  Link it all up and, if you've done it all properly, you should find the pool cover now responds when you touch the switch.

 

 

 

 

 

Link to comment
Share on other sites

Woww !!

Well all I can say is thank you very much for this.  Seems I now have various options open to me.  As I said not looking for freebie scripts just some help with all this, which I have certainly got from all that replied.

Thank you very much to all of you.  I will now pop off and give all this a go :)

 

Link to comment
Share on other sites


Xiija wrote:

 incomplete ?
:)

hrm.., it works for me.

the listen fires every time the switch is touched, regardless of what the message is.

should act just like a touch in the pool cover....

Yes, it works when you do it that way, but it's incomplete because you have lost some functionality in the pool script. Your method opens and closes the pool cover regardless of what the message is, and it acts just like a touch in the pool cover, but it means that you can no longer touch the pool cover itself to open and close it.  You have to use the switch instead.  Rather than disabling the touch_start event, I suggest creating a new listen event that listens for the toggle switch and offers a second way of opening and closing the cover without disabling the original way

As an aside, a toggle switch that sends a binary (ON/OFF) message also offers more information than one that just sends a pulse.  It's not just saying "activate the cover". You can use that extra information about the state of the cover to do other things, if you wanted to (turn on a light in the house to let the owner know that the pool is uncovered, for example).  That sort of thing wasn't in the OP's question, but the potential is there once you add a toggle switch that sends its state. If the OP doesn't want that option, the dirt-simple alternative is to make a "switch" by modifying the basic "Hello, avatar!" script to broadcast on channel -9876 instead of public chat.

Link to comment
Share on other sites


Innula Zenovka wrote:

We all found scripting difficult when we started, but it's not too hard once you stop telliing yourself it is.   I "knew" I couldn't script until I had an argument with someone who'd sold me a door script that didn't do what I wanted, and I thought "if an idiot like that can make scripts, even ones that don't work right, I can certanly do it better. How difficult can opening and closing a door be, anyway?".

 

jejejejejje (:

is the slippery slope that is (:

Link to comment
Share on other sites

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