Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need Script Help Please!

Lankarion Lock
Thread Killer
Join date: 9 Oct 2006
Posts: 48
07-28-2009 00:16
I have a login/logout commission tip jar script, but there's only one thing that I dont like about it. When a group member is logged into the tip jar and a second person with the correct group active clicks on the jar, it immediately logs the first person out and logs the clicker in.
I've tried to modify the script myself the best I can but I can't seem to quite get it right. What i'd like is for it to tell the second clicker to please wait to log in until the first person is logged out.

I believe what I have to change is somewhere in here and would greatly appreciate any help.

touch_start(integer nr)
{
key toucher = llDetectedKey(0);
if (!llSameGroup(toucher))
{
llInstantMessage(llDetectedKey(0), "Please activate the proper group title to use this tip jar.";);
return;
}

if (toucher == keyactive)
{
user = NULL_KEY;
nameactive = "";
totaldonated = 0;
llSetText("Touch To Log In",< 255,0,0>,1.0);
llSetPayPrice(PAY_HIDE, [PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
}
else
{
key user = llDetectedKey(0);
keyactive = keyactive;
nameactive = llKey2Name(toucher);
llSetText(nameactive+"'s Tip Jar\nL$0 Donated So Far",< 0,255,0>, 1.0);
llSensorRepeat("", toucher, AGENT, 96, PI, 60.0);
llSetPayPrice(PAY_DEFAULT, [PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT]);
}
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
Tip Jar
07-28-2009 00:49
I have added a condition for 'in use'
If it is not nothing is changed, otherwise an IM is send to the toucher.
CODE

touch_start(integer nr)
{
key user;
key toucher = llDetectedKey(0);
if (!llSameGroup(toucher))
{
llInstantMessage(llDetectedKey(0), "Please activate the proper group title to use this tip jar.");
return;
}

if (toucher == keyactive)
{
user = NULL_KEY;
nameactive = "";
totaldonated = 0;
llSetText("Touch To Log In",< 255,0,0>,1.0);
llSetPayPrice(PAY_HIDE, [PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
}
else
{
if ( user == NULL_KEY )
{
user = llDetectedKey(0);
keyactive = keyactive;
nameactive = llKey2Name(toucher);
llSetText(nameactive+"'s Tip Jar\nL$0 Donated So Far",< 0,255,0>, 1.0);
llSensorRepeat("", toucher, AGENT, 96, PI, 60.0);
llSetPayPrice(PAY_DEFAULT, [PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT]);
}
else llInstantMessage( llDetectedKey(0), "You must wait, the Tip Jar is taken by: "+ nameactive );
}
Happy Scripting:)
I have not done anything to debug your code.
The way 'keyactive' is used looks mysterious, but I don't know all the code.
_____________________
From Studio Dora
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
07-28-2009 01:06
I'm guessing that may not work because the "user" variable is global in the OP's code, but local to the handler in Dora's. Maybe just removing the "key user;" line from the top would make it work.

What makes me hesitate here is the existence of both "user" and "keyactive" variables, and the mysterious "keyactive = keyactive;" statement. I agree with Dora that, for a quick fix, the "user" variable is probably easier than trying to disentangle whatever "keyactive" does in the rest of the script (because it's a little confuzzled in this section).

(Another tiny annoyance with this code is that it creates the "toucher" local variable yet keeps calling llDetectedKey(0) over and over again afterwards. Not wrong, but extra work.)
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
07-28-2009 02:26
From: Qie Niangao
I'm guessing that may not work because the "user" variable is global in the OP's code, but local to the handler in Dora's. Maybe just removing the "key user;" line from the top would make it work.
You are right. The 'user' variable should be made global and initialized to NULL_KEY.
I changed it a without thinking much, because it was defined originally in some odd place down the line:)
_____________________
From Studio Dora
Lankarion Lock
Thread Killer
Join date: 9 Oct 2006
Posts: 48
Oops!
07-28-2009 04:04
Yeah that was my fault, I accidentally posted one that I had attempted to change and obviously failed at!

This is the original without a mysterious user thrown in there

touch_start(integer nr)
{
key toucher = llDetectedKey(0);
if (!llSameGroup(toucher))
{
llInstantMessage(llDetectedKey(0), "Please activate the proper group title to use this tip jar.";);
return;
}

if (toucher == keyactive)
{
keyactive = NULL_KEY;
nameactive = "";
totaldonated = 0;
llSetText("Touch To Log In",< 255,0,0>,1.0);
llSetPayPrice(PAY_HIDE, [PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
}
else
{
key toucher = llDetectedKey(0);
keyactive = toucher;
nameactive = llKey2Name(toucher);
llSetText(nameactive+"'s Tip Jar\nL$0 Donated So Far",< 0,255,0>, 1.0);
llSetPayPrice(PAY_DEFAULT, [PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT]);
}
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
07-28-2009 04:32
Then it becomes:
CODE

touch_start(integer nr)
{
key toucher = llDetectedKey(0);
if (!llSameGroup(toucher))
{
llInstantMessage(llDetectedKey(0), "Please activate the proper group title to use this tip jar.");
return;
}

if (toucher == keyactive)
{
keyactive = NULL_KEY;
nameactive = "";
totaldonated = 0;
llSetText("Touch To Log In",< 255,0,0>,1.0);
llSetPayPrice(PAY_HIDE, [PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
}
else
{
if ( keyactive == NULL_KEY )
{
key toucher = llDetectedKey(0);
keyactive = toucher;
nameactive = llKey2Name(toucher);
llSetText(nameactive+"'s Tip Jar\nL$0 Donated So Far",< 0,255,0>, 1.0);
llSetPayPrice(PAY_DEFAULT, [PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT, PAY_DEFAULT]);
}
else llInstantMessage( llDetectedKey(0), "You must wait, the Tip Jar is taken by: "+ nameactive );
}

'keyactive' must be global and initialized (in the state_entry()) to keyactive = NULL_KEY
You have two local variables: key toucher = llDetectedKey(0);
That is silly. You should clean up the use of 'toucher' and 'llDetectedKey()' as Qie suggested.
Happy scripting:)
_____________________
From Studio Dora