PDA

View Full Version : libnotice


Novo
05-01-2007, 03:51 PM
/***
*** Notification Centre (libnotice ) ***
+(void) addObsrver( object, recall, event );
+(void) remObserver( object );
-(void) postNotification( event, {params} );
***/

public function addObserver( object, recallEvent, event )
{
for ( temp.notice: this.notifications )
{
if ( temp.notice[0] != object )
continue;
if ( temp.notice[1] != recallEvent )
continue;
if ( temp.notice[2] != event )
continue;

return;
}

this.notifications.add( {object, recallEvent, event } );
return;
}

public function remObserver( object )
{
for ( i = 0; i < this.notifications.size(); i ++ )
{
if ( this.notifications[i][0] == object
|| this.notifications[i][0] == null ) // Shouldn't be here!
{
this.notifications.delete( i );
i --;
continue;
}
}

return;
}

function postNotification( event, param )
{
temp.eventParams = { this };
temp.eventParams.addarray( param );

for ( temp.notice: this.notifications )
{
if ( temp.notice[2] != event )
continue;

( temp.notice[0] ).trigger(
temp.notice[1],
temp.eventParams );
}
return;
}

killerogue
05-01-2007, 04:22 PM
All of what exactly can this be used for, I had assumed for things like notices based on the time of the server.

But I wasn't really sure...was I right?

Novo
05-01-2007, 06:00 PM
All of what exactly can this be used for, I had assumed for things like notices based on the time of the server.

But I wasn't really sure...was I right?

Example of use:

Putting it into a 'onDamage' clause in the player so that guild members can see other guild members health...

killerogue
05-01-2007, 11:11 PM
:O, awesome. I'll definitely be using it. Thanks Novo.

cbk1994
05-01-2007, 11:47 PM
This seems like something nice, I will probably end up using it. Novo-can you please leave an explanation of what your code is, and what it does when you post? Thanks.

Novo
05-02-2007, 12:02 AM
This seems like something nice, I will probably end up using it. Novo-can you please leave an explanation of what your code is, and what it does when you post? Thanks.

I thought I did! It is a broadcast system. Basically, you have Observers... And Events. Observers check to see if an event happened. They are interested when something happens. They may be anyone -- Jews, Russians, and even Christians at times. When the object does something, they signal a broadcast using 'postNotification( event )'. This sends an event to all the objects interested in THAT event. This allows them to do coordinate their efforts.

NPC1:

function onCreated()
{
join("libnotice");
scheduleevent(5, "Incoming", null);
}

function onIncoming()
{
echo("Got it!");
postNotification("got it");
}



NPC2:

function onCreated()
{
NPC1.addObserver( this, "GotIt", "got it" );
}

function onGotIt()
{
echo("Do you get it too?");
}


Of course -- Try not to make an event post an event that makes the initial event be posted... Such as adding this line to NPC1:

this.addObserver( this, "Incoming", "got it" );

cbk1994
05-02-2007, 12:30 AM
stuff

Thanks Novo again, GREAT script, didn't realize how nice that script is. I will DEFINATLY use it!

Novo
05-02-2007, 01:25 AM
Thanks Novo again, GREAT script, didn't realize how nice that script is. I will DEFINATLY use it!

That smells sarcasm so badly. :( Let me go in my room and write a suicide note.