Jump to content

Requesting Assistance Touch Based Script


TomixDragoon
 Share

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

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

Recommended Posts

Hello, I am Tomix, and I am new to scripting LSL. I was wondering how I would be able to create a touch limit on an Object. The Limit being one, I already have the object playing a sound and increasing a count by one per click, sort of like signing a guestbook.

vector  color = <0.5, 1.0, 1.0>;
string  default_text = "//default_text// \n ";
string  text;
string sound1 = "sound1"; //uuid or name of item in inventory
string sound = "sound"; //uuid or name of item in inventory

integer count=0;
 
default
{
    state_entry()
    {
        text = default_text;
        llSetText(text, color, 1.5);
        
        llTargetOmega(<0,0,.2>,PI,1.0);
    }
    
    touch_start(integer total_num)
    {
        llTriggerSound(sound1, 2.0);

        llTriggerSound(sound, 2.0);
    }

    touch_end(integer number)
    {
        count = count + 1;
        text = (string)count + "//new_text// \n";
        llSetText(text, color, 1.5);
    }

}

 

Link to comment
Share on other sites

If you mean that each person can only click once, you will need to create a list in which you collect the UUIDs of each person who touches the object. Then, each time anyone touches it, search the list to see if that person's UUID is already on the list.  If so, allow the action to occur.  If not, deny it.  If you have very many people touching your object, this will create a problem after a while, because the script will run out of memory when the list gets too large.  One way to beat that is to monitor how much free memory the script still has, and start deleting the oldest UUIDs, one at a time, as new people click.  A less elegant way is to periodically delete the entire list (or reset the script) and start all over. Take a look at http://wiki.secondlife.com/wiki/User:Rolig_Loon/High-Capacity_Greeter-Counter  for an example of a script that uses these strategies (triggered in a timer event instead of a touch_start event, but the actions are exactly the same).

Incidentally, there's no particular reason for separating actions into a touch_start event and a touch_end event in a script like this. Any of the actions that you identify could take place in either event, since there's no preferred order for doing them.  The only possible exception is with your two sounds.  As written, they will happen simultaneously, so you will onl;y hear the second one.  If you really want to hear both, then put the second one in the touch_end event.  If the first touch is really short (or if people release the mouse button very slowly), you will hear both sounds in order.

EDIT: Oh, and the maximum volume for a sound is 1.0.

Edited by Rolig Loon
Link to comment
Share on other sites

This little example should show you the basic method for recording who touches things, and for behaving differently depending on whether they've touched the item before or not::

list lTouchers;

default {
	touch_start(integer num_detected) {
		key kToucher = llDetectedKey(0);
		if(!~llListFindList(lTouchers, [kToucher])){
			lTouchers +=[kToucher];
			llRegionSayTo(kToucher, 0, "Since you have not touched me before, I am adding you to the list of touchers.");
		}
		else{
			llRegionSayTo(kToucher, 0,"You have touched me already so I am not bothering to add you a second time.");
		}
	}
}

Bear in mind that, without attention, the list lTouchers will eventually get so long that the script runs out of memory and you get a stack heap collision error.    There's various ways round this.   You might, for example, check llGetListLength(lTouchers) when you add a new record and, if it's over a certain length, use llDeleteSubList to remove the first few items from the list.

Link to comment
Share on other sites

12 hours ago, TomixDragoon said:

Taking into account the sound, thank you Rolig, I want it the device to record someone who touches it, and if they touch it again it doesn't increase the counter again or play the noise again.

Good, so I guessed correctly.  The steps Innula and I described will do it.  Study the script I pointed you to, and Innula's example.

Link to comment
Share on other sites

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