x = x + 2 for 2 hours... How can I do this?
|
|
Guido Columbia
Registered User
Join date: 25 Oct 2005
Posts: 102
|
04-16-2006 09:55
I need help to edit the function below. Heres what I'm trying to do and just can't figure out. When touched, x = x + 1 --- But only for 2 hours.
Say box is touched at 1:00pm (x=1) Again at 1:10pm (x=2) Again at 1:30pm (x=3) ...
How can I make this happen: At 3pm x = x - 1; (x = 2) At 3:10pm x = x - 1; (x = 1) At 3:30pm x = x - 1; (x = 0) ...
Sleep & timers dont seem to be yeilding the desired result, even when called from another script via link message.
In the script Im working on I already have a timer event set for 12 minutes. I even tried making a count every time the timer event was called and if the count = 10 (2 hours) x = x - 1.. That was an undesired result becaue it would simply make x = x - 1 every 2 hours, not make x = x - 1 for 2 hours from the point it was touched.
I also put a 7200second (2 hour) sleep event in a seperate script which would make x = x - 1 at end of 7200 seconds. Again I believe this was an undesired result because when touched a 2nd time minutes later the script is asleep. (wait 2 hours, x=x-1, wait 2 hours, x=x-1)..
I want: touch, x=x+2, wait 2 hours from that point, x=x-1 -- and have that happen no matter how many times touched.
What I have tried seemed to reset timer, or wait till first process was done before executing next.
If you need more elaboration, please let me know.
Thanks in advance for any help.
----
integer x = 0;
increasetemp() {
x = x + 1; // but only for 2 hours, then x = x - 1
}
default { state_entry() { }
touch_start(integer nada) {
increasetemp();
}
}
|
|
Kazanture Aleixandre
Here I am.
Join date: 5 Oct 2005
Posts: 524
|
04-16-2006 10:29
From: Guido Columbia I need help to edit the function below. Heres what I'm trying to do and just can't figure out. When touched, x = x + 1 --- But only for 2 hours.
Say box is touched at 1:00pm (x=1) Again at 1:10pm (x=2) Again at 1:30pm (x=3) ...
How can I make this happen: At 3pm x = x - 1; (x = 2) At 3:10pm x = x - 1; (x = 1) At 3:30pm x = x - 1; (x = 0) ...
Sleep & timers dont seem to be yeilding the desired result, even when called from another script via link message.
In the script Im working on I already have a timer event set for 12 minutes. I even tried making a count every time the timer event was called and if the count = 10 (2 hours) x = x - 1.. That was an undesired result becaue it would simply make x = x - 1 every 2 hours, not make x = x - 1 for 2 hours from the point it was touched.
I also put a 7200second (2 hour) sleep event in a seperate script which would make x = x - 1 at end of 7200 seconds. Again I believe this was an undesired result because when touched a 2nd time minutes later the script is asleep. (wait 2 hours, x=x-1, wait 2 hours, x=x-1)..
I want: touch, x=x+2, wait 2 hours from that point, x=x-1 -- and have that happen no matter how many times touched.
What I have tried seemed to reset timer, or wait till first process was done before executing next.
If you need more elaboration, please let me know.
Thanks in advance for any help.
----
integer x = 0;
increasetemp() {
x = x + 1; // but only for 2 hours, then x = x - 1
}
default { state_entry() { }
touch_start(integer nada) {
increasetemp();
}
} integer x = 0; integer a=1; changetemp() { x = x + a; // but only for 2 hours, then x = x - 1 } timer() { a=-1; //stop timer here } default { state_entry() { //set timer here for 2 hours } touch_start(integer nada) { changetemp(); } }
|
|
SteveR Whiplash
teh Monkeh
Join date: 24 Sep 2004
Posts: 173
|
04-16-2006 11:02
Ok.. You want to increase x everytime it's touched. But if it's been 2 hours or more since the first time it was touched, you want to decrease x. Right? If I follow you right, then you don't need timers or sleeps at all. You simply need to check the timestamp everytime the object is touched. integer x; float time = 0;
default { touch_start(integer num_detected){ if (time == 0){ // first touch time = llGetTime(); // get time x = 1; // x is now 1 } else if (llGetTime() - time < 7200){ // less than 7200 seconds (2 hours) x++; // increment x } else { // more than 2 hours x--; // deincrement x } llOwnerSay((string)x); // what is x now? } }
|
|
Guido Columbia
Registered User
Join date: 25 Oct 2005
Posts: 102
|
04-16-2006 12:04
Thank you both very much for your suggestions. I believe steve is pretty close to what I want to do. >> But if it's been 2 hours or more since the first time it was touched, you want to decrease x. Right? Actually, not exactally what I was trying to do. The value of x must increase by 1 for 2 hours every time it is touched, not just the first time. In your example if I touched once, then again 1.5 hours later the value would decrease by 2 a half hour after the last touch. -- Not the goal. Touch (x=1) -- Touch 1.5 hour after that (x=2) -- 30 mins after that x = 1 again -- 1.5 hours after that x=0 It also has to work no matter how many times touched. I can't seem to figure it out.. Your suggestions so far have helped me narrow the field a bit. Thank you very much for the help. If you have any other ideas please let me know. 
|
|
SteveR Whiplash
teh Monkeh
Join date: 24 Sep 2004
Posts: 173
|
04-16-2006 12:13
AHHA! I think I see what you're going for now. You're probably going to need to keep a list of every time it was touched and then run a timer to clear the list as 2 hours pass for each one. Lemme play with it for a bit and I'll show you what I mean.
|
|
SteveR Whiplash
teh Monkeh
Join date: 24 Sep 2004
Posts: 173
|
04-16-2006 12:40
Here we go. I shortened the times so you can test it quickly. list touches;
default { touch_start(integer num_detected){ touches += [llGetTime()]; // add time of touch to the list if (llGetListLength(touches) == 1){ // first touch so start the timer llSetTimerEvent(5); } } timer(){ integer numtouches = llGetListLength(touches); // get touch count integer i; for (i = 0; i < numtouches; i++){ // loop through list if (llGetTime() - llList2Float(touches, i) > 20){ // been long enough? touches = llDeleteSubList(touches, i, i); // delete it } } numtouches = llGetListLength(touches); // get new count if (numtouches == 0){ // no touches so kill timer llSetTimerEvent(0); } // show how many touches llSetText((string)numtouches, <1,1,1>, 1); } }
One problem with this way is that if you get a lot of touches the list will use up too much memory and cause the script to error. To prevent that, you might want to keep a list of intervals instead. Each entry in the list would be a count of how many times it was touched in that interval. And then as time passes you can clear those entries. But I'm not sure if that would be suitable for what you're doing or not.
|
|
SteveR Whiplash
teh Monkeh
Join date: 24 Sep 2004
Posts: 173
|
04-16-2006 13:10
And here's an interval version. It keeps a count of touches for each 15 minute interval. list intervals = [0,0,0,0,0,0,0,0];
CountTouches(){ integer x; integer i; for (i = 0; i < 8; i++){ // loop through entries x += llList2Integer(intervals, i); // add counts } llSetText((string)x, <1,1,1>, 1); // show count }
default { state_entry(){ llSetTimerEvent(900); // 15 minute timer } touch_start(integer num_detected){ integer count = llList2Integer(intervals, 0); // get count count++; // increment count intervals = llListReplaceList(intervals, [count], 0, 0); // update count CountTouches(); } timer(){ intervals = llListInsertList(intervals, [0], 0); // make new entry intervals = llDeleteSubList(intervals, -1, -1); // delete last entry CountTouches(); } }
|
|
Guido Columbia
Registered User
Join date: 25 Oct 2005
Posts: 102
|
04-16-2006 13:49
Humm, I think I can impliment this.. I'll see and let you know.. Thanks for your help! Too bad they dont have a simple function like llSetVariableTimer(x,1,20) -- to set x=x+1 for 20 minutes.. Hehe, it seems like a simple thing until you try to do it.. 
|
|
Guido Columbia
Registered User
Join date: 25 Oct 2005
Posts: 102
|
04-16-2006 21:09
I already had a timer event in my main script so I created a new script and used link messages to communicate. Even setting the timer event to diffrent intervals it seems to send the "Decrease" link message multiple times in a row even if the prim is clicked 20 seconds apart. Still not percisely correct. I am using this in a script to provide money so it has to be pretty percise. Does the code below look correct? ---- list touches;
default {
timer(){ integer numtouches = llGetListLength(touches); // get touch count integer i; for (i = 0; i < numtouches; i++){ // loop through list if (llGetTime() - llList2Float(touches, i) > 50){ // been long enough? llMessageLinked(LINK_SET, 0, "Decrease", NULL_KEY); touches = llDeleteSubList(touches, i, i); // delete it } } numtouches = llGetListLength(touches); // get new count if (numtouches == 0){ // no touches so kill timer llSetTimerEvent(0); } // show how many touches }
link_message(integer sender_num, integer num, string str, key id) { if (str == "Increase") { touches += [llGetTime()]; // add time of touch to the list if (llGetListLength(touches) == 1){ // first touch so start the timer llSetTimerEvent(1); } } } }
|
|
SteveR Whiplash
teh Monkeh
Join date: 24 Sep 2004
Posts: 173
|
04-16-2006 22:06
Yeah, that should get it to work with the link messages. I'd say use the interval version with shorter intervals. Instead of 8 intervals of 15 minutes, maybe 24 intervals of 5 minutes? I wouldn't trust the list method with my money because it's prone to crashing if you get enough clicks within the 2 hours. Of course, I guess if it crashes you just won't pay out 
|
|
Guido Columbia
Registered User
Join date: 25 Oct 2005
Posts: 102
|
04-17-2006 01:00
I will have to figure something else out then.  Thank you very much Steve for your time and effort, it is very much appreciated. Very creative method. I may figure out another way to do what I am wanting. Out of curiosity if anyone else can concieve of a method to accoplish what I'm trying to do I'd love to see it.  Thanks again for your time & help. I've been working for days on a project and figured out every other little problem, this one seems to have stopped me dead in my tracks..
|