Reply
Innula Zenovka
Posts: 7,040
Registered: ‎06-02-2009
0 Kudos

Re: Using a switch ?

Reply to shaun Mosswood - view message

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 process
float   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.

 

 

 

 

 

Honored Resident
shaun Mosswood
Posts: 79
0 Kudos

Re: Using a switch ?

Reply to shaun Mosswood - view message

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 :smileyhappy:

 

Rolig Loon
Posts: 25,017
Registered: ‎10-05-2009
0 Kudos

Re: Using a switch ?

[ Edited ]

Reply to Xiija - view message


Xiija wrote:

 incomplete ? :smileyhappy:

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.

Not as dumb as I look
Member 16
Member
16
Posts: 2,853
0 Kudos

Re: Using a switch ?

Reply to Innula Zenovka - view message


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 (: