Author Topic: init() causes WRITE before entering room  (Read 6226 times)

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
init() causes WRITE before entering room
« on: April 03, 2008, 10:08:36 am »
I am still struggling with an init() issue.

I want an NPC to react when a player brings a specific item into the room. The problem is, that all my efforts to write such a routine, cause the WRITE to execute before the player actually enters the room.

What the player sees in the room:
s
Boobay says: I see you have the gem of eternity with you.
Archway of Heroes.
Boobay, the superhero.

Here was my first attempt to code this. This is in the room file right after the configure() fun.
Code: [Select]
notify_enter(ob) {
x=sizeof(filter(all_inventory(this_player()),(: load_name($1)=="players/detah/heroquest/obj/gem" :)));
    if(present("boobay") && x>0) {
      write("Boobay says: I see you have the gem of eternity with you.\n");
      return 1;
    }
}

Then I tried a variant on the same theme, trying to slow it down. by using the same fun with a callout with a delay of 5 seconds. It was still instantaneous when the player typed south. I tried 25 delay and got the same result.

Here is my second attempt to code this:
Code: [Select]
init() {
  ::init();
    if(objectp(this_player())) { /*players are objects, therefore always TRUE*/
    gem_check();
    }
}

[further down in the same room file]

menlos_check() {
    x=sizeof(filter(all_inventory(this_player()),(: load_name($1)=="players/detah/heroquest/obj/gem" :)));
    if(present("boobay") && x>0) {
      write("Boobay says: I see you have the gem of eternity with you.\n");
      return 1;
    }
}
Again, same results. the WRITE occurs before the player enters the next room.
Any suggestions how to fix this?

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
Re: init() causes WRITE before entering room
« Reply #1 on: April 03, 2008, 10:11:02 am »
EDIT
In my second code block in my previous post, that function should not read menlos_check, it is actually called gem_check(). I bungled the copy/paste.

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: init() causes WRITE before entering room
« Reply #2 on: April 03, 2008, 10:32:43 pm »
Disclaimer: I have never used this mudlib and/or driver.

init() and notify_enter() are probably being called immediately upon your player being moved into the room, by the same code that moves him in. The easiest way I can think of is to use a call_out() to delay when your code is called. Using a time of 0 seconds _should_ make it execute immediately after the current call stack is empty, but you'll have to test to see for sure.

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
Re: init() causes WRITE before entering room
« Reply #3 on: April 04, 2008, 08:04:23 am »
I already tried the callout approach. No matter what delay you put on it, it still executes instantly. Theres something special about init apparantly that tells it to bypass the callout delay. Thanks for the suggestion.

I solved this last night. I used a catch_tell -style function, to capture the "Detah enters." text in the NPC's code. It is pretty simple code its just a sscanf inside the catch_tell fun.

WOOHOO! Gornak is now done. I am having several other wizards testplay it now.

Thanks.
Detah