Jump to content
TomixDragoon

Requesting Assistance Touch Based Script

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);
    }

}

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...