Thread: libnotice
View Single Post
  #6  
Old 05-01-2007, 11:02 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Quote:
Originally Posted by cbkbud View Post
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" ); 
Reply With Quote