only one...
|
Tadao Nordenskiold
Registered User
Join date: 9 May 2009
Posts: 37
|
11-02-2009 03:46
I'm nor sure what to name this thread, and I don't know what to search for either to find the answer, so I hope someone can help me out.
If I have a script with an touch_start(), and are setting: key toucher = llDetectedKey(0); How do I make sure that only the one clicking can use the script?
If John Doe starts to use the object containing the script, Jane Doe mustn't be able to use the script at the same time.
This is linked scripts aswell, so when the end-script is reached, it needs to unlock the object so that the next user can start interacting with the object.
|
Niall Braveheart
Registered User
Join date: 5 Oct 2008
Posts: 27
|
11-02-2009 04:03
A couple of ideas spring to mind
1) make toucher a global variable, and test to see if it's "empty" in the touch event. if it is then continue, remember to set it back to null once you've finished processing. if it isn't then just drop out of the touch event
or
2) change the state, and don't include a touch event in the new state just change the state back when your finished
|
Jeredin Denimore
Romani Ite Domum
Join date: 5 Jul 2008
Posts: 95
|
11-02-2009 04:17
Try something like... key currentToucher; default { state_entry() { currentToucher = NULL_KEY; } touch_start(integer num_detected) { currentToucher = llDetectedKey(0); state next_stuff_to_do; } } state next_stuff_to_do { state_entry() { // do lots of stuff // do even more stuff // done doing stuff, go back to default state default; } touch_start(integer num_detected) { if (currentToucher != llDetectedKey(0)) { llInstantMessage(llDetectedKey(0),"Someone is currently using this object."); } } }
|
Jeredin Denimore
Romani Ite Domum
Join date: 5 Jul 2008
Posts: 95
|
11-02-2009 04:18
Heh it appears all I did was illustrate Niall's answer with a concrete example 
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
11-02-2009 04:34
A caveat. State changes in touch_starts are a bit borked. See https://jira.secondlife.com/browse/SVC-3017What you would need to do, particularly if there's a touch event in the second state, is something like touch_start(integer number_detected){ currentToucher = llDetectedKey(0); } touch_end(integer num){ state next_stuff; }
|
Jeredin Denimore
Romani Ite Domum
Join date: 5 Jul 2008
Posts: 95
|
11-02-2009 04:50
Ahh good point, I knew of that caveat but my fingers forgot it when I typed the code 
|
Tadao Nordenskiold
Registered User
Join date: 9 May 2009
Posts: 37
|
11-02-2009 05:21
Hmm.. for some reason, I am not able to post my reply?! But this comes through??
Edit: I simply can't add my answer, so instead, I am attaching it in an text file...sorry. :/
|
Niall Braveheart
Registered User
Join date: 5 Oct 2008
Posts: 27
|
11-02-2009 05:47
Well i think the reason you couldn't post your reply is the word S-E-L-E-C-T
But,
not sure about the number of HTTPRequest per script so i'll assume you are right in that it can only be one. (I'm sure others wil correct us if it's wrong)
Assuming PlanSelector.lsl and mailer.lsl are in the same prim (or linkset) tou could use link messages ( llMessageLinked ) from mailer.lsl and planselector.lsl should be able to receive the message and act accordingly.
|
Tadao Nordenskiold
Registered User
Join date: 9 May 2009
Posts: 37
|
11-02-2009 05:55
Hmm.. when you say it.. se-lect might be a reason.  So.. if I am thinking the same way you are.. are you suggesting something like the following: PlanSelector.lsl state default { // Do all stuff here and move to next state }
state active { // Set var toucher to current toucher, lock object to user, do all stuff, and move to state listen }
state listen { // listen for linked message from mailer.lsl // if message received, unlock by moving back to state active }
That's the first thing I come to think of when reading your reply.
|
Niall Braveheart
Registered User
Join date: 5 Oct 2008
Posts: 27
|
11-02-2009 06:43
Yes something like that would work in the llistening state in PlanSelector.lsl you would need something like link_message(integer sender_num, integer num, string msg, key id) {
// do whatever needs to be done
}
and in the mailer.lsl llMessageLinked(LINK_THIS, 0, "message text","");
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
11-02-2009 07:31
You don't need change states, at least not to avoid the multiple toucher problem. (You probably still need the extra states for the rest of your job, though). Niall suggested another approach early on. This code is untested, but it ought to work ...... integer touched; key av; integer finished; integer CHAN; integer handle;
init() { llInstantMessage(av, "Thank you, " + llKey2Name(av) + ". Good bye!"); touched = 0; av = ""; finished = FALSE; llListenRemove(handle); llSetTimerEvent(0); // And do whatever you need in order to unlock the linked object }
default { touch_start (integer num) { ++touched; if (touched == 1) { av = llDetectedKey(0); llSetTimerEvent(180); handle = llListen(CHAN,"","",""); llInstantMessage(av,"You will have 3 minutes to complete this task"); } if( touched >= 1) { if (av != llDetectedKey(0)) { llInstantMessage(llDetectedKey(0), "Sorry, I'm busy with another customer. Please wait."); return; } // Do stuff that involves, say, touching the object 24 times. // You could obviously figure other ways to determine when the task is finished // but, to follow this example, ........... if (touched == 25) { finished = TRUE; } if (finished) { init(); } } }
timer() { llDialog(av, "Do you need more time?" ["YES","NO"], CHAN); }
listen (integer channel, string name, key id, string msg) { if (msg == "YES") { llSetTimerEvent(60); llInstantMessage(av,"Clock reset for an additional minute."); } else { init(); } } }
Incidentally, there's nothing wrong with using the word "select." I can write "select" as many times as I like in a post. See? "Select, select, select." Once I have typed it, however, I am not allowed to type the word " f-r-o-m."
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Niall Braveheart
Registered User
Join date: 5 Oct 2008
Posts: 27
|
11-02-2009 07:42
From: Rolig Loon Incidentally, there's nothing wrong with using the word "select." I can write "select" as many times as I like in a post. See? "Select, select, select." Once I have typed it, however, I am not allowed to type the word " f-r-o-m."
Thanks for clarifying that, it makes more sense for it to be a combination of words otherwise the like of delete, update, insert etc would have the same problem
|