Author Topic: Trying to augment the verb 'enter' - no clue what I'm doing  (Read 2927 times)

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Trying to augment the verb 'enter' - no clue what I'm doing
« on: September 16, 2011, 06:08:51 pm »
problem is as follows:  'enter book' works.  'enter book chapter 1' is apparently not receiving an object.

/lib/verbs/rooms/enter.c
Code: [Select]
#include <lib.h>
#include "include/enter.h"

inherit LIB_VERB;

static void create(){
    verb::create();
    SetVerb("enter");
    SetRules("into OBJ", "OBJ", "OBJ STR");
    SetErrorMessage("Enter what?");
    SetHelp("Syntax: enter <PLACE>\n"
            "        enter into <PLACE>\n\n"
            "Moves you into the place you specify.  Whereas the \"go\" "
            "command is designed for motion towards something, the "
            "\"enter\" command is designed for motion into something.\n"
            "See also: go");
}

mixed can_enter_obj(){
    if( this_player()->GetParalyzed() ){
        return "You cannot do anything, because you are paralyzed.";
    }
    if(!stringp(hobbled(this_player()))) return "Your injuries prevent easy movement. Perhaps you should try crawling.";
    return 1;
}

mixed can_enter_into_obj(){
    return can_enter_obj();
}

mixed can_enter_obj_str( object obj, string str2 ){
write(sprintf("%%^CYAN%%^can_enter_obj_str()%%^RESET%%^ called with obj=%O str2=%s",obj,str2));
return can_enter_obj();
}

mixed do_enter_obj(object targ, string what){
write(sprintf("%%^CYAN%%^do_enter_obj()%%^RESET%%^ called with targ=%O what=%s",targ,what));
    return targ->eventEnter(this_player(), remove_article(lower_case(what)));
}

mixed do_enter_into_obj(object targ, string what) {
    do_enter_obj(targ, what);
}

mixed do_enter_obj_str( object targ, string what, string where ){
this_player()->eventPrint(sprintf("%%^CYAN%%^do_enter_obj_str()%%^RESET%%^ called with targ=%O what=%s where=%s",targ,what,where));
return 1;//targ->eventEnter( this_player(), remove_article( lower_case( what ) ) );
}

/geographybook.c
Code: [Select]
#include <lib.h>

inherit LIB_STORAGE;

mixed direct_enter_obj(){ return 1; }
mixed direct_enter_into_obj(){ return direct_enter_obj(); }
private string s_title = "Geography";
private object o_home = children( "/domains/interlibrary/obj/shelf01" )[0] || new( "/domains/interlibrary/obj/shelf01" );
//private object o_library = environment( o_home );
private object o_library = find_object( "/domains/interlibrary/room/library" );
private object *o_exits = ({
"/domains/campus/room/start",
"/domains/town/room/vill_road1"
});

int eventEnter( object o_who, string s_what, string s_where ){
int i_ret, i_ch;
string s_enter, s_exit, s_que, s_prep;

write( sprintf( "%%^CYAN%%^eventEnter()%%^RESET%%^ in geography called with o_who=%O s_what=%s s_where=%s", o_who, s_what, s_where ) );

if( GetClosed() ){
write( "You cannot enter the book while it's closed." );
say( o_who->GetName() + " stares at the cover of their book." );
return 0;
}
return 1;
}

string GetLong(){
string s_long;
int i_count, i_countmax;
if( environment( this_player() ) != o_library ){
write( "The book '" + s_title + "' dissolves into purple mist, vanishing from your inventory!" );
this_object()->SetClosed( 1 );
this_object()->eventMove( o_home );
tell_room( o_library, "The book '" + s_title + "' flickers into existence on " + o_home->GetShort() + "." );
return "";
}
if( this_object()->GetOpen() == 1 ){
s_long  = "Strange, magical energies infuse the crisp, vellum leaves of this leatherbound tome, drawing ";
s_long += "your attention inwards, inwards.  Richly-crafted illuminations, dazzling to behold and preceding ";
s_long += "each chapter, are so compelling that you suppose you could very well enter them.\n";
s_long += "This book has the following chapters:  ";
i_countmax = sizeof( o_exits );
for( i_count = 0; i_count < i_countmax; i_count++ ){
s_long += "Chapter %^BOLD%^" + ( i_count + 1 ) + "%^RESET%^, ";
s_long += "%^BOLD%^" + o_exits[i_count]->GetShort() + "%^RESET%^";
if( i_countmax > 1 && i_count < i_countmax - 1 ){ s_long += "; "; }
}
}else{
s_long  = "Strange, magical energies infuse the soft, indigo velvet-bound cover of this book, on which is ";
s_long += "inscribed in gold leaf the title '" + s_title + "'.  Who knows what you might find when you open ";
s_long += "this book?";
}
return s_long;
}

void create() {
::create();
SetKeyName( "book" );
SetId( ({ "book" }) );
SetAdjectives( ({ "plain", "small", lower_case( s_title ), s_title }) );
SetShort( "a '" + s_title + "' book" );
SetLong( (: GetLong :) );
SetMass( 2 );
SetMaxCarry( 0 );
SetBaseCost( "silver", 1000 );
SetCanClose( 1 );
SetClosed( 1 );
}

void init(){ ::init(); }

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Re: Trying to augment the verb 'enter' - no clue what I'm doing
« Reply #1 on: September 16, 2011, 09:12:30 pm »
And here's a stripped-down version that highlights the problem point:

/verbs/rooms/enter.c
Code: [Select]
#include <lib.h>
#include "include/enter.h"

inherit LIB_VERB;

static void create(){
    verb::create();
    SetVerb("enter");
    SetRules("STR in OBJ");
    SetErrorMessage("Enter what?");
}

mixed can_enter_str_in_obj( string str, object obj ){
write(sprintf("%%^CYAN%%^can_enter_str_in_obj()%%^RESET%%^ called with str=%s obj=%O",str,obj));
return 1;
}

mixed do_enter_str_in_obj( string str, object obj ){
this_player()->eventPrint(sprintf("%%^CYAN%%^do_enter_str_in_obj()%%^RESET%%^ called with str=%s obj=%O",str,obj));
return 1;
}

/geographybook.c
Code: [Select]
#include <lib.h>

inherit LIB_STORAGE;

mixed indirect_enter_str_in_obj(){ return 1; }

int eventEnter( string s_str, object o_obj ){
write( sprintf( "%%^CYAN%%^eventEnter()%%^RESET%%^ in geography called with s_str=%O o_obj=%O", s_str, o_obj ) );
return 1;
}

void create() {
::create();
SetKeyName( "book" );
SetId( ({ "book" }) );
SetAdjectives( ({ "plain", "small" }) );
SetShort( "a 'Geography' book" );
SetLong( "Blah blah blah" );
SetMass( 2 );
SetMaxCarry( 0 );
SetBaseCost( "silver", 1000 );
SetCanClose( 1 );
SetClosed( 1 );
}

void init(){ ::init(); }

obj is being 0, and don't know why.

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Re: Trying to augment the verb 'enter' - no clue what I'm doing
« Reply #2 on: September 17, 2011, 10:33:43 am »
PROBLEM SOLVED.

Turns out it needed to be direct_enter_str_in_obj(), not indirect_... since I only have one object.  :P