Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

last time touch it and compare time...

Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
10-29-2007 17:45
hievery one I get this script from the wiki
when I touch the object give to me the las time in second I touched.Is possible compare the las time touched and the new touched event and compare the time ...if the first time and the last time have a diference like 24 hours (86400 seconds) do something if whas not do another one?
CODE


default {
state_entry()
{
llResetTime();
}
touch_start(integer num_touch)
{
float time = llGetTime(); //Instead getting, and then resetting the time, we could use llGetAndReset() to accomplish the same thing.
llResetTime();
llSay(0,(string)time + " seconds have elapsed since the last touch." );
}
}



Maybe can make it with llGetWallclock(); and store the key or name in a list and compare from there?I know how store the key or name of the avatar in a list, but is possible store the time too in the same list or i need another list for that info?
I found this tread
/54/b4/32100/1.html
and make some similar or maybe not but I dont know how implement in this tipe of script.

All help is very appreciated.
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
10-29-2007 18:18
Yes, is possible.

Add global variable before default {}

float lastTime = -1;;

default
{

...

}

Then, in touched {}, add

if ( *compare time and lastTime here * )
do something;

lastTime = time;



Details left as exercise for student.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-29-2007 18:22
CODE

default {
touch_start(integer num_touch)
{
float time = llGetTime();
if(time >= 86400)//24 * 60 * 60 = 86400
{
llSay(0, "Do something");
}
else
{
llSay(0, "Do something else");
}
llResetScript();//resetting the script resets the time
}
}
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
10-30-2007 17:28
ok, but.. i dont get it
I post my code here, maybe some one can see what I try to make.

CODE


list menuList = ["2","20","10","0"]; // answer options
string objeto_inv;
key user;

integer CHANNEL;
integer HANDLE;
integer usado=1;//used
integer cantidad=5;//amount of gift to give
list lstGiven;
integer tiempo;//time
list lstintento;//trys

givegift()
{
//llTriggerSound("candrop2",1.0);
llSay(0,"here is your " + objeto_inv + ",enjoy it!");
llGiveInventory(user,objeto_inv);
}

sounddenied()
{
llTriggerSound("2818b39c-c95e-bc22-1c8a-5b09f3a3494a",1.0);
}


default
{

state_entry()
{


llSetText( " Left " + (string)cantidad + " Gift \n Touch me \n answer correctly \n the cuestion \n and get your gift ",<1,1,1>,1);




}


touch_start(integer total)//change

{
usado=1;
user = llDetectedKey(0);

//if(llSameGroup(user) == TRUE)
//{
if(llListFindList(lstGiven+lstintento, [user]) != -1)
{sounddenied();
llInstantMessage(user, "you already get your gift try another days");
llInstantMessage(user, "or already get your oportunity");
state default;
}
if (llListFindList(lstGiven, [user]) == -1)

{ if(total>=1)
{



{ if (llListFindList(lstGiven, [user]) == -1 && cantidad <=5 )
{ llSay(0," esta siendo usado por:"+llKey2Name(user));
state menu_gift;
}




else
{ llInstantMessage(user, "sorry but the gift box already give the maximun gift today.");
state default;
}

}

}

}

}
}

//}


//end default
state menu_gift
{
state_entry()
{

CHANNEL = llRound(llFrand(1000000) - 10000000);
HANDLE = llListen(CHANNEL, "", user, "");
llSetTimerEvent(15);
llDialog(user, "how many fingers you have?", menuList, CHANNEL);

}


listen(integer channel, string name, key id, string message)
{


if (message == "2")
{sounddenied();

llInstantMessage(user, "wrong answer try in another moment");
lstintento = (lstintento=[]) + lstintento + [user];
state default;
}
if (message == "20")
{
objeto_inv="gift";
givegift();
cantidad--;
llTriggerSound("eb514b16-097b-6121-45f4-7117729c61ec",1.0);
lstGiven = (lstGiven=[]) + lstGiven + [user];
state default;
}

if (message == "10")
{sounddenied();
llInstantMessage(user, "wrong answer try in another moment");
lstintento = (lstintento=[]) + lstintento + [user];

state default;
}
if (message == "0")
{sounddenied();
lstintento = (lstintento=[]) + lstintento + [user];
llInstantMessage(user, "wrong answer try in another moment");
state default;
}







}

timer()
{
llSay(0,"time is over try again");
state default;
}
state_exit()
{
llSetTimerEvent(0);
llListenRemove(HANDLE);
}


}



Im trying to store not only the user trys , the time when he/she make a wrong answer for compare the new touch and if whas 5 minutes (for example) past since the last touch he/she can make a new try and if whas not, the object says "try in 5 minutes again".

PD:sorry for my bad english ;)
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
11-09-2007 12:11
Any sugestion?
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-09-2007 14:27
If no one else gets to it before, I'll take a look at it later tonight Papalopulus.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
11-09-2007 14:44
thanks Jesse!
all help is very appreciated ;)
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-09-2007 16:41
OK 1st off I know you are just learning so you might as well learn this also :) The formatting was bad, really bad.

For example, you can do this:
From: someone

if(whatever){
do something here:
}

or you can write it like this:

if(whatever)
{
do something here:
}

But you never, ever what to do this:
From: someone

if(whatever)
{do something here
}

It makes the code unreadable and it won't indent correctly. ANd while you are at it, take out some of the spaces. For more you can read here:

http://www.cheesefactory.us/lslwm/StyleGuide.htm

OK my rant is over and now to your code:

CODE

list menuList = ["2","20","10","0"]; // answer options
string objeto_inv;
key user;
integer CHANNEL;
integer HANDLE;
integer usado=1;//used
integer cantidad=5;//amount of gift to give
list lstGiven;
list lstintento;//trys

givegift()
{
//llTriggerSound("candrop2",1.0);
llSay(0,"here is your " + objeto_inv + ",enjoy it!");
llGiveInventory(user,objeto_inv);
}

sounddenied()
{
llTriggerSound("2818b39c-c95e-bc22-1c8a-5b09f3a3494a",1.0);
}


default
{
state_entry()
{
llSetText( " Left " + (string)cantidad + " Gift \n Touch me \n answer correctly \n the cuestion \n and get your gift ",<1,1,1>,1);
}

touch_start(integer total)//change
{
usado=1;
user = llDetectedKey(0);
//if(llSameGroup(user) == TRUE)
//{
if(llListFindList(lstGiven + lstintento, [user]) != 1)
{
sounddenied();
llInstantMessage(user, "you already get your gift try another days");
//llInstantMessage(user, "or already get your oportunity");
}
if (llListFindList(lstGiven, [user]) == -1)
{
if(total>=1)
{
if (llListFindList(lstGiven, [user]) == -1 && cantidad <=5 )
{
llSay(0," esta siendo usado por:"+llKey2Name(user));
state menu_gift;
}
else
{
llInstantMessage(user, "sorry but the gift box already give the maximun gift today.");
}
}
}
}
}


state menu_gift
{
state_entry()
{
CHANNEL = llRound(llFrand(1000000) - 10000000);
HANDLE = llListen(CHANNEL, "", user, "");
llSetTimerEvent(15);
llDialog(user, "how many fingers you have?", menuList, CHANNEL);
}

listen(integer channel, string name, key id, string message)
{
if (message == "2")
{
sounddenied();
llInstantMessage(user, "wrong answer try in another moment");
lstintento = (lstintento=[]) + lstintento + [user];
state default;
}
if (message == "20")
{
objeto_inv="gift";
givegift();
cantidad--;
llTriggerSound("eb514b16-097b-6121-45f4-7117729c61ec",1.0);
lstGiven = (lstGiven=[]) + lstGiven + [user];
state default;
}

if (message == "10")
{
sounddenied();
llInstantMessage(user, "wrong answer try in another moment");
lstintento = (lstintento=[]) + lstintento + [user];
state default;
}
if (message == "0")
{
sounddenied();
lstintento = (lstintento=[]) + lstintento + [user];
llInstantMessage(user, "wrong answer try in another moment");
state default;
}
}

timer()
{
llSay(0,"time is over try again");
state default;
}
state_exit()
{
llSetTimerEvent(0);
llListenRemove(HANDLE);
}
}

You can not make the if test like this:

if(llListFindList(lstGiven + lstintento, [user]) != 1)

It will only check the 1st list, so ethier make it like this:

if(llListFindList((lstGiven, [user]) != -1 && (llListFindList(lstintento, [user]) != -1)

or break it down to an if test inside another if test. As far as testing for time, you don't have an if test anywhere testing the time. I also don't see anywhere you have declared what the maximum number of tries is. If you are going to try to assign how many times each user has tried then you are probably going to end up having to use a strided list with the integer of tries following the key of the user in the list.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
11-09-2007 17:11
thanks for the correct code format ;)
the numbers of trys is only one time per avatar in case they take the correct answer or mke a mistake if the avtar dont have the correct answer the need to wait until the time for answer is over because if they make a wrong choice they cant participate again until I clear the list reseting the script.
and the amount of objects decrease here :

CODE

if (message == "20")
{
objeto_inv="gift";
givegift();
cantidad--; //Amount of objects -1(the total was declared here at the begining with integer cantidad=5;
llTriggerSound("eb514b16-097b-6121-45f4-7117729c61ec",1.0);
lstGiven = (lstGiven=[]) + lstGiven + [user];
state default;
}


And the thing with the time is, I whant to give for example one gift per day to each avatar so maybe I need take the time when the avatar take the gift an compare with the next try , maybe I can reset the script for clear the list or clear the first keys from the list each day
but if one avatar touch the object 10 mintues before midnight for example he can take again the gift 1 second past midnight and not 24 hours later like I whant.
I have the idea how make this but I dont know what function i need to use .
llGetTime() llGetTimeStamp() llGetWallClock() etc .
Brigme some light Jesse;)
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-09-2007 17:26
somewhere in ther you are going to need to store extra values, I suggest these

integer vgIntTimeout = 3600; //--1hr in seconds
integer vgIntMaxStorage = 50; //--number of names to store
list vgLstNames;
list vgLstTimes;

then in your touch...
CODE

//-- check to see if they are in our list
integer vIntSearch = llListFindList( vgListNames, llDetectedName( 0 ) );
if (~vIntSearch){
//-- if they are, check to see if they've waited long enough
if (llGetTime() - llList2Float( vgListTimes ) > vgIntTimeout){
//-- they waited long enough, remove them from the list
vgListTimes = llDeleteSubList( vgListTimes , vIntSearch, vIntSearch );
}else{
//-- the didn't wait long enough, leave them in and skip the rest of the code
llInstantMessage( llDetectedKey( 0 ), "You have to wait" );
return;
}
}
//-- add them to the list (shortest wait times will always be first this way)
vgLstNames = (list)llDetectedName( 0 ) + llList2List( vgLstNames, 0, vgIntMaxStorage - 2 );
//-- add their time, so we can check it later
vgLstTimes = (list)llGetTime() + llList2List( vgLstTimes, 0, vgIntMaxStorage - 2 );
//-- code to give stuff away
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -