Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   libnotice (https://forums.graalonline.com/forums/showthread.php?t=73780)

Novo 05-01-2007 02:51 PM

libnotice
 
PHP Code:

/***
*** Notification Centre (libnotice ) ***
+(void) addObsrver( object, recall, event );
+(void) remObserver( object );
-(void) postNotification( event, {params} );
***/

public function addObserverobjectrecallEventevent )
  {
  for ( 
temp.noticethis.notifications )
    {
    if ( 
temp.notice[0] != object )
      continue;
    if ( 
temp.notice[1] != recallEvent )
      continue;
    if ( 
temp.notice[2] != event )
      continue;
    
    return;
    }

  
this.notifications.add( {objectrecallEventevent } );
  return;
  }

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

  return;
  }

function 
postNotificationeventparam )
  {
  
temp.eventParams = { this };
  
temp.eventParams.addarrayparam );

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

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


killerogue 05-01-2007 03: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 05:00 PM

Quote:

Originally Posted by killerogue (Post 1304863)
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 10:11 PM

:O, awesome. I'll definitely be using it. Thanks Novo.

cbk1994 05-01-2007 10: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-01-2007 11:02 PM

Quote:

Originally Posted by cbkbud (Post 1304927)
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:
PHP Code:

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

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

NPC2:
PHP Code:

function onCreated()
  {
  
NPC1.addObserverthis"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:
PHP Code:

this.addObserverthis"Incoming""got it" ); 


cbk1994 05-01-2007 11:30 PM

Quote:

Originally Posted by Novo (Post 1304930)
stuff

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

Novo 05-02-2007 12:25 AM

Quote:

Originally Posted by cbkbud (Post 1304937)
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.


All times are GMT +2. The time now is 05:24 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.