|
Psistorm Ikura
Registered User
Join date: 19 Jul 2006
Posts: 52
|
12-10-2006 11:05
hi fellows
Ive currently run into a problem which has me puzzled as to its solution: basically my code is supposed to be like this:
while (something = true){ (do stuff) (random wait) (repeat) }
now this works easily - but I need to interrupt the loop by a listen. Ive used a timer, and it works ok, BUT: I cant interrupt the script for a listen whilst it is running. Ive used a timer, but the problem is the random wait, it has to change on each pass of the timer. thus the actual script time spent in the timer() event must be minimal and the wait has to take place outside of it. basically it would work to re-set the timer with a random value each time the timer() event was called. is there any way to accomplish this?
|
|
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
|
12-10-2006 11:53
From: Psistorm Ikura hi fellows
Ive currently run into a problem which has me puzzled as to its solution: basically my code is supposed to be like this:
while (something = true){ (do stuff) (random wait) (repeat) }
now this works easily - but I need to interrupt the loop by a listen. Ive used a timer, and it works ok, BUT: I cant interrupt the script for a listen whilst it is running. Ive used a timer, but the problem is the random wait, it has to change on each pass of the timer. thus the actual script time spent in the timer() event must be minimal and the wait has to take place outside of it. basically it would work to re-set the timer with a random value each time the timer() event was called. is there any way to accomplish this? Yes, just call llSetTimerEvent with a new random value during the timer event itself.
|
|
Psistorm Ikura
Registered User
Join date: 19 Jul 2006
Posts: 52
|
12-10-2006 11:55
yeah, that fixed it for me, actually figured it out a few minutes ago x_X thanks for the answer anyways!
|
|
Psistorm Ikura
Registered User
Join date: 19 Jul 2006
Posts: 52
|
12-10-2006 13:09
something I might well append here: right now I do this:
state_entry() llsettimerevent(random) llListen(blablabla) if (condition) { bla; }
timer() bla llsettimerevent
the problem is: the if statement is only polled once during the execution of the script, it seems. shouldnt it be polled each time timer() is exited?
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-10-2006 14:23
From: Psistorm Ikura something I might well append here: right now I do this:
state_entry() llsettimerevent(random) llListen(blablabla) if (condition) { bla; }
timer() bla llsettimerevent
the problem is: the if statement is only polled once during the execution of the script, it seems. shouldnt it be polled each time timer() is exited? I'd say yes to that, but its dependant on what exactly you are trying to do. The state_entry code is only run once at state entry or reentry.If the if statement needs to be processed every time then it does need to be in the timer event handler. What are you using the listen to to do? What you dont appear to take into account is that a listen is an event, so once you set it up it will be running waiting for input. So it is not in the main loop of execution once started. I'd be inclined to write this more like this default { state_entry() { Initialise(); llListen(channel,"","",""); llSetTimerEvent(0.1); // trigger almost immediately } timer() { if(condition) { DoSomething(); } llSetTimerEvent(llFrand(maxtimer) + mintimer); }
listen(integer number, string name, key id, string message) { } }
|
|
Psistorm Ikura
Registered User
Join date: 19 Jul 2006
Posts: 52
|
12-11-2006 09:27
thanks for the answer. thats what I ended up doing after some fiddling, actually. now Im almost where I want to be, but I encountered one last problem I cant figure out. for this Ill attach the script here //Global variables integer listenchannel = 42; //listen channel - dur :P float bmax = 15.0; //max wait between blinking float bmin = 10.0; //min wait between blinking //"no twiddle!" variables integer idleness = 1; integer blink = 0; float blinkTresh = 20.0; //Functions
doBlink() { llSetTextureAnim(FALSE, 0, 2, 2, 0, 0, 10.0); llSetTextureAnim(ANIM_ON|REVERSE|PING_PONG,ALL_SIDES, 2, 2, 4, 4, 10.0); blinkTresh = 2.0 * llFrand((bmax - bmin) + bmin); }
setAfk() { if (idleness == 1) { idleness = 0; llSetTextureAnim(ANIM_ON,ALL_SIDES, 2, 2, 1, 0.0, 10.0); } }
//Script default { on_rez(integer start_param) { llResetScript(); } state_entry() { llListen(42, "", llGetOwner(),""); llSetTimerEvent(0.5); } listen (integer channel, string name, key id, string message) { message = llToLower(message); if (message == "close") { setAfk(); } else if (message == "open") { idleness = 1; doBlink(); } } timer() { if (llGetAgentInfo(llGetOwner()) & AGENT_AWAY) { llOwnerSay("Im afk"); setAfk(); } if (idleness == 1) { if (blink >= blinkTresh) { doBlink(); blink = 0; } else { blink++; } } } }
now what goes wrong here is apparently, that the condition that checks for AGENT_AWAY never triggers. Ive checked other scripts which place this check inside a timer function, and THEY work like a charm.. probably just a stupid error Ive overlooked, but I cant see where things go bananas. any help is greatly appreciated  another edit: script still isnt working as intended. my afk mode works ok, but: the script just doesnt trigger! please check the above script for errors, because I cant see em D: many thanks in advance. my suspicion is that AGENT_AWAY is simply buggy, because it triggered once in about 50 tries for me...
|