Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Simple Online Notifier?

Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
09-06-2009 16:12
So, I figured out how to get a script to IM when someone is online. Obviously this was hacked together in a couple minutes. It just IM's me every 30 seconds if my key is showing online.

CODE


key user_key = "f5c35057-fb7c-4f20-a384-07a604c18766";

default
{
state_entry()
{

llSetTimerEvent(30);

}

dataserver(key queryid, string data)
{

if (data == "1") llInstantMessage("f5c35057-fb7c-4f20-a384-07a604c18766", "Paul is online.");

}

timer()
{
llRequestAgentData( user_key, DATA_ONLINE);
}

}



What would I have to do with this to get it to only IM the first time it detects the key come online? Or would that require a complete rewrite of the script?
_____________________
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
09-06-2009 16:16
Put a call to llSetTimerEvent with a value of 0.0 inside the timer event itself to turn off the timer repeats.
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
09-06-2009 16:30
Call me crazy, but that's not sinking in.

Add llSetTimerEvent(0.0);
just before llRequestAgentData( user_key, DATA_ONLINE); ?

Wouldn't that make it stop working completely?
_____________________
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
09-06-2009 16:32
Put a global variable at the top of the script to remember what the last result was. Only IM yourself if the result is different from the last execution AND the newest result is that you are online.
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
09-06-2009 16:35
From: Hewee Zetkin
Put a global variable at the top of the script to remember what the last result was. Only IM yourself if the result is different from the last execution AND the newest result is that you are online.


I like how that sounds. Clueless as I am though, I gotta ask for an example.
_____________________
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
09-06-2009 16:53
Hewee's way (which makes more sense than mine as it will work if you log and relog):

CODE

key user_key = "f5c35057-fb7c-4f20-a384-07a604c18766";
integer i_am_online = FALSE;
default
{
state_entry()
{
llSetTimerEvent(30);
}
dataserver(key queryid, string data)
{
if ((data == "1") && (!i_am_online))
{
llInstantMessage("f5c35057-fb7c-4f20-a384-07a604c18766", "Paul is online.");
i_am_online = TRUE;
}
else
{
i_am_online = FALSE;
}
}
timer()
{
llRequestAgentData( user_key, DATA_ONLINE);
}
}
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
09-06-2009 17:20
From: EF Klaar
Hewee's way (which makes more sense than mine as it will work if you log and relog):

CODE

key user_key = "f5c35057-fb7c-4f20-a384-07a604c18766";
integer i_am_online = FALSE;
default
{
state_entry()
{
llSetTimerEvent(30);
}
dataserver(key queryid, string data)
{
if ((data == "1") && (!i_am_online))
{
llInstantMessage("f5c35057-fb7c-4f20-a384-07a604c18766", "Paul is online.");
i_am_online = TRUE;
}
else
{
i_am_online = FALSE;
}
}
timer()
{
llRequestAgentData( user_key, DATA_ONLINE);
}
}


Except that won't correctly set 'i_am_online' if it true and you are online. I would go for something more like setting 'i_am_online = (integer)data;' at the end instead.
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
09-06-2009 17:28
I made a few changes, for clarity's sake.

In this version, there are no IMs being sent. Instead, the prim will simply change colour based on whether the person is online or not. I've slowed the online check, because I really feel that it's not necessary to know with 30 seconds, but I've also made it a global variable. But the biggest feature I added, was support for placing the target's UUID in the object description. Once you've done that, you can wait til the next timed check, or click the prim, and it will update and check immediately.

There are still refinements that could be done.. you could add hovertext that showed the object's name.. (which you could then name the name of the person).. you could of course use a side number instead of ALL_SIDES, and make a nice panel with the person's pecture, and a small panel that lit up when they were online. You could change the colours to textures, and swap images that said "online" and "offline" under the person's name. (personally I just use the LED look).

CODE


key watchKey; // place target's UUID in object's description
integer wasOnline = FALSE;
vector colorOnline = <0,1,0>;
vector colorOffline = <0,0.25,0>;
float checkRate = 60; // Do you REALLY need to check more than once a minute?

default
{
state_entry()
{
llSetColor(colorOffline, ALL_SIDES);
llSetTimerEvent(0.1); // run NOW
}

on_rez(integer start) // reset on rezzing.
{
llResetScript();
}

touch_start(integer num) // reset when touched.
{
llResetScript();
}

dataserver(key queryid, string data)
{
if ((integer)data != FALSE)
{
if (wasOnline == FALSE)
{
llSetColor(colorOnline , ALL_SIDES);
wasOnline = TRUE;
}
else
{
llSetColor(colorOffline , ALL_SIDES);
wasOnline = FALSE;
}
}
}

timer()
{
watchKey = (key)llGetObjectDesc();
llRequestAgentData(watchKey, DATA_ONLINE);
llSetTimerEvent(checkRate);
}
}


_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
09-06-2009 17:35
That's a whole lot more effective, but I'd rather have the IM's than color changing. IM's will be sent to me when I'm offline. Color changes will not.

It's a good script though, I'll have to play with that too. Looks like I could switch out llSetColor for InstantMessage and that would do the job? Or would I just get the IM every 60 seconds?
_____________________
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
09-06-2009 17:48
From: Hewee Zetkin
Except that won't correctly set 'i_am_online' if it true and you are online. I would go for something more like setting 'i_am_online = (integer)data;' at the end instead.
I must be getting tired or something; but surely if I am online and "i_am_online" is set to TRUE then it is already correctly set.

If the dataserver event says I am online and the variable says I'm not, then my online staus has changed; a notification should be sent and the variable updated to reflect the fact that I am now online.

If the dataserver event says I am online and the variable also says I am then there has been no change in my online status since the previous notification; so no further notification needs to be sent and the variable doesn't need to be updated.

And if the dataserver says I'm not online then it's probably quicker to just set the variable to reflect this each time rather than to test to see if it actually needs to be updated.

What have I missed?

Doh!

Yes I see now; iut should read like this:

CODE

key user_key = "f5c35057-fb7c-4f20-a384-07a604c18766";
integer i_am_online = FALSE;
default
{
state_entry()
{
llSetTimerEvent(30);
}
dataserver(key queryid, string data)
{
if (data == "1")
{
if (!i_am_online)
{
llInstantMessage("f5c35057-fb7c-4f20-a384-07a604c18766", "Paul is online.");
i_am_online = TRUE;
}
}
else
{
i_am_online = FALSE;
}
}
timer()
{
llRequestAgentData( user_key, DATA_ONLINE);
}
}
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
09-06-2009 18:12
Sorry, Paul. I am tired.
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
09-06-2009 18:18
From: EF Klaar
Sorry, Paul. I am tired.


Not a problem, I'm learning a lot from this thread. Although I just tested your script in a prim on my alt- it only seemed to work correctly the very first time my alt logged in. After that, the script had to be reset for it to work again.
_____________________
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
09-06-2009 18:52
From: Paul Wardark
That's a whole lot more effective, but I'd rather have the IM's than color changing. IM's will be sent to me when I'm offline. Color changes will not.

It's a good script though, I'll have to play with that too. Looks like I could switch out llSetColor for InstantMessage and that would do the job? Or would I just get the IM every 60 seconds?


the wasOnline toggle is what makes it work so it's "only when status is changed". so yes, you could just drop the instant message in there.

But keep in mind, you could leave it as colour change without IMs, and just wear this as a HUD.. then you'd know whenever the person was on or off.. and it wouldn't be IMing you while you were offline.

That's one of the big weaknesses of things like this, they'll IM you when the person logs on, but they won't tell you IF they're online when you want to know if they are or not. (like if they were already logged on before you logged on). the simpler colour change makes it much easier to know if someone IS ONLINE or not, NOW.
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
09-06-2009 18:56
From: Winter Ventura
the wasOnline toggle is what makes it work so it's "only when status is changed". so yes, you could just drop the instant message in there. You could also wear this as a HUD.. then you'd know whenever the person was on or off.. and it wouldn't be IMing you while you were offline.

That's one of the big weaknesses of things like this, they'll IM you when the person logs on, but they won't tell you IF they're online when you want to know if they are or not. (like if they were already logged on before you logged on). the simpler colour change makes it much easier to know if someone IS ONLINE or not, NOW.



Actually, in my case, it's more important to me to get it when I'm offline. When I'm online, I can just send 'em an IM myself and that tells me if they're online. I don't need this for when I'm online. I want to leave this in my house to warn me when I'm offline and can't check manually.
_____________________
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
09-07-2009 10:18
From: EF Klaar
If the dataserver event says I am online and the variable also says I am then there has been no change in my online status since the previous notification; so no further notification needs to be sent and the variable doesn't need to be updated.

Sorry about that. You are correct. I got confused about the level of nesting of the 'else'.
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
09-07-2009 11:30
From: Hewee Zetkin
Sorry about that. You are correct. I got confused about the level of nesting of the 'else'.

No, you were right; I combined two tests that should have been nested. I then posted the corrected script. My logic was good, but the execution was flawed. One late night too many :)
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
09-07-2009 13:09
From: Winter Ventura
I made a few changes, for clarity's sake.

In this version, there are no IMs being sent. Instead, the prim will simply change colour based on whether the person is online or not. I've slowed the online check, because I really feel that it's not necessary to know with 30 seconds, but I've also made it a global variable. But the biggest feature I added, was support for placing the target's UUID in the object description. Once you've done that, you can wait til the next timed check, or click the prim, and it will update and check immediately.

There are still refinements that could be done.. you could add hovertext that showed the object's name.. (which you could then name the name of the person).. you could of course use a side number instead of ALL_SIDES, and make a nice panel with the person's pecture, and a small panel that lit up when they were online. You could change the colours to textures, and swap images that said "online" and "offline" under the person's name. (personally I just use the LED look).

CODE


key watchKey; // place target's UUID in object's description
integer wasOnline = FALSE;
vector colorOnline = <0,1,0>;
vector colorOffline = <0,0.25,0>;
float checkRate = 60; // Do you REALLY need to check more than once a minute?

default
{
state_entry()
{
llSetColor(colorOffline, ALL_SIDES);
llSetTimerEvent(0.1); // run NOW
}

on_rez(integer start) // reset on rezzing.
{
llResetScript();
}

touch_start(integer num) // reset when touched.
{
llResetScript();
}

dataserver(key queryid, string data)
{
if ((integer)data != FALSE)
{
if (wasOnline == FALSE)
{
llSetColor(colorOnline , ALL_SIDES);
wasOnline = TRUE;
}
else
{
llSetColor(colorOffline , ALL_SIDES);
wasOnline = FALSE;
}
}
}

timer()
{
watchKey = (key)llGetObjectDesc();
llRequestAgentData(watchKey, DATA_ONLINE);
llSetTimerEvent(checkRate);
}
}




By the way, I tried this one. It doesn't work. The prim shows green even when the target is offline.
_____________________
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
09-07-2009 13:23
I don't know if it's lag in the region or what, but it seems like these scripts are really slow to respond, or only work once they're reset...
_____________________
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
09-07-2009 13:26
From: Winter Ventura
I made a few changes, for clarity's sake.

In this version, there are no IMs being sent. Instead, the prim will simply change colour based on whether the person is online or not. I've slowed the online check, because I really feel that it's not necessary to know with 30 seconds, but I've also made it a global variable. But the biggest feature I added, was support for placing the target's UUID in the object description. Once you've done that, you can wait til the next timed check, or click the prim, and it will update and check immediately.

There are still refinements that could be done.. you could add hovertext that showed the object's name.. (which you could then name the name of the person).. you could of course use a side number instead of ALL_SIDES, and make a nice panel with the person's pecture, and a small panel that lit up when they were online. You could change the colours to textures, and swap images that said "online" and "offline" under the person's name. (personally I just use the LED look).

CODE


key watchKey; // place target's UUID in object's description
integer wasOnline = FALSE;
vector colorOnline = <0,1,0>;
vector colorOffline = <0,0.25,0>;
float checkRate = 60; // Do you REALLY need to check more than once a minute?

default
{
state_entry()
{
llSetColor(colorOffline, ALL_SIDES);
llSetTimerEvent(0.1); // run NOW
}

on_rez(integer start) // reset on rezzing.
{
llResetScript();
}

touch_start(integer num) // reset when touched.
{
llResetScript();
}

dataserver(key queryid, string data)
{
if ((integer)data != FALSE)
{
if (wasOnline == FALSE)
{
llSetColor(colorOnline , ALL_SIDES);
wasOnline = TRUE;
}
else
{
llSetColor(colorOffline , ALL_SIDES);
wasOnline = FALSE;
}
}
}

timer()
{
watchKey = (key)llGetObjectDesc();
llRequestAgentData(watchKey, DATA_ONLINE);
llSetTimerEvent(checkRate);
}
}





Just for laughs, I tried this, using a 10 second timer instead of 60. I'm watching the color change every ten seconds now. Online, offline. Online, offline. And this is happening whether the target is online or offline.
_____________________
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
09-07-2009 13:46
CODE

string avKey = "0bf93171-e0d3-4b8c-b6eb-55d2cc30cf26";
integer isOnline;
vector colorOnline = <0, 1, 0 >;
vector colorOffline = <1, 0, 0 >;
float checkRate = 60;

default {
on_rez(integer start_param) {
llResetScript();
}
state_entry() {
llSetColor(colorOffline, ALL_SIDES);
llRequestAgentData(avKey, DATA_ONLINE);
llSetTimerEvent(checkRate);
}
dataserver(key queryid, string data) {
integer dataInt = (integer)data;
if (dataInt && !isOnline) {
llSetColor(colorOnline, ALL_SIDES);
}
else if (!dataInt && isOnline){
llSetColor(colorOffline, ALL_SIDES);
}
isOnline = dataInt;
}
timer() {
llRequestAgentData(avKey, DATA_ONLINE);
}
}
_____________________
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