Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

AGENT_AWAY bugged?

Psistorm Ikura
Registered User
Join date: 19 Jul 2006
Posts: 52
12-14-2006 13:57
hey fellows.. Ive posted something quite related a few days before, but the actual question this thread about occured a few posts down in my old thread and was left unanswered. so after waiting a decent amount of time - and assuming noone spotted my question - Im gonna give it another shot, this time specifically enquiring about a problem:
I do a check if the object owner is in away state, and poll the if statement its in every 0.5 seconds. yet, when I hit the /afk and my char flops into away mode, the script does nothing at all. I inserted a debug line with llOwnerSay, but it just doesnt set off!

Ive checked, double-checked and triple-checked my checks, also compared to a similar script which seems to be working. but i cant figure it out for the life of me. so either the AGENT_AWAY condition is broken/bugged, or there a really stupid error with my script.
Id be grateful if anyone could look at it and toss me any mistakes I mightve made - many thanks in advance.

CODE

//Blinking Script by Psistorm Ikura
//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|PING_PONG,ALL_SIDES, 2, 2, 1, 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(listenchannel, "", 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 (idleness == 1 & llGetAgentInfo(llGetOwner()) & AGENT_AWAY) { //here be FAIL D:
setAfk();
}
else if (idleness == 0 & llGetAgentInfo(llGetOwner()) & !AGENT_AWAY) { //basically the reverse check of above, checks if agent has returned from away
doBlink();
idleness ==1;
}

if (idleness == 1) {
if (blink >= blinkTresh) {
doBlink();
blink = 0;
}
else {
blink++;
}
}
}
}


Ive narrowed it down on the first line after calling the timer() handler - any simple operations executed after this line is true fail, thus the line never does become true.
any help is hugely appreciated, since I really want this script working :)
2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
12-14-2006 14:07
I have no idea what the resto of your script does, but I can see that you are using the bitwise AND operator ( & ) when it looks like your intent is the logical AND operator ( && ).

Change the '&' to '&&' and see if that makes a difference.

You can find out more about the difference between bitwise and logical operators here (a mirror of the LSL wiki):

http://rpgstats.com/wiki/index.php?title=Operators
Psistorm Ikura
Registered User
Join date: 19 Jul 2006
Posts: 52
12-14-2006 14:33
Ive tried replacing the bitwise & with &&, but now the script check triggers at the first startup of the script, when Im definitely NOT in away mode o_O
2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
12-14-2006 14:41
woops...sorry about that....my last comment was too general.

Change the 1st line in your timer to:

CODE

if (idleness == 1 && (llGetAgentInfo(llGetOwner()) & AGENT_AWAY)) { //here be FAIL D:


Note where the && and & operators reside.

Do something similar for the 4th line....
CODE

else if (idleness == 0 && (llGetAgentInfo(llGetOwner()) & !AGENT_AWAY)) { //basically the reverse check of above, checks if agent has returned from away


Beyond that...I have not really looked through the rest of your script.

Hope this helps.
Psistorm Ikura
Registered User
Join date: 19 Jul 2006
Posts: 52
12-14-2006 14:52
hmm.. the line doesnt trigger right away anymore - but also it doesnt trigger at all :/
did several checks, modded the script like you advised, rezzed a box, put it in, added a llOwnerSay test line and hit the afk mode - but nothing, even after waiting a few seconds...

edit: hmm re-enabling the "afk on idle" option in the debug menu fixed it mostly.
now the only thing not working is the "back from afk" line... that one wont fire

edit2: SOLVED! :D

I ripped out the llGetAgentInfo line, since !AGENT_AWAY compiled, but didnt seem to return reliable results. I whipped up a check as follows:
if the agent is away, set x to 1, else set it to 0
this check is run every 0.5 seconds now, giving the script a sweet response time. one last question remains though: I re-assign a value to a variable any 0.5 seconds. is this critical, memory wise? or does the value just get overwritten and thus not fill up any stack or heap space? :)
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
12-15-2006 13:17
If you are looking to see if AGENT_AWAY is NOT set, then you can check the result of a bitwise AND:

CODE

else if (idleness == 0 && !(llGetAgentInfo(llGetOwner()) & AGENT_AWAY)) { //basically the reverse check of above, checks if agent has returned from away


otherwise you are just testing if the value AGENT_AWAY is non-zero, which will always evaluate TRUE. I moved the ! to outside the paretheses, so it checks the result of the & operation which is what you want it to do.
Psistorm Ikura
Registered User
Join date: 19 Jul 2006
Posts: 52
12-17-2006 12:12
ahh thats also a nice solution :)
I shall include this in the next revision of the script!