Author Topic: Functionals in room descriptions (attn Crat)  (Read 2284 times)

Offline janua

  • Acquaintance
  • *
  • Posts: 12
    • View Profile
Functionals in room descriptions (attn Crat)
« on: August 09, 2012, 12:25:58 pm »
I'm trying to understand how to write dynamic room descriptions, so I hit the books and wrote this based on the example docs/build/Rooms Part 2: Advanced Room Building.


Code: [Select]
#include <lib.h>
#include ROOMS_H

inherit LIB_ROOM;

string checkDoor(string unused);

void create() {
    room::create();
    SetClimate("outdoors");
    SetAmbientLight(30);
    SetShort("West Gate of Medienne");
    SetNightLong(0);
    SetDayLong(0);
    SetLong( (: checkDoor :) );
    SetItems(([
        ({ "cobble", "cobbles", "cobblestones", "road", "street", "cobbled", "cobbled street", "cobbled road", "cobblestone road", "cobblestone street" }) : "The smoothly worn street is paved with irregular, rounded stones that are tightly fitted together.",
        ({ "wall", "walls", "thick wall", "thick walls" }) : "The wall is made of heavy, gray stone blocks carefully fitted together. It tapers slightly toward the top, where a walkway allows patrols to keep watch over the town.",
      ]));
    SetExits( ([
        "west" : "/domains/medienne/room/med_wgateout",
        "east" : "/domains/medienne/room/main_celm.c",
      ]) );
    SetClimate("temperate");

    SetDoor("west", "/domains/medienne/doors/portcullis_west.c");

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

string checkDoor(string unused){
    string tmp = "The cobbled road intersects with Medienne's thick wall here, and a large, arched opening allows passage out of the town.";
    if( (int)"/domains/Medienne/doors/portcullis_west"->GetOpen()  )
        tmp += " The bottom edge of an open portcullis can be seen in the arch.";
    else tmp += " The opening is blocked by a lowered portcullis.";
    tmp += " A lever is mounted on the wall next to the opening.";
    return tmp;
}



The room description doesn't change when I open the gate. It always reads, "The cobbled road intersects with Medienne's thick wall here, and a large,
arched opening allows passage out of the town. The opening is blocked by a lowered portcullis. A lever is mounted on the wall next to the opening." So the function is working, but the if never evaluates to true.

The way the if statement is written is strange to me, so I tried writing the it like this:
Code: [Select]
if( "/domains/Medienne/doors/portcullis_west"->GetOpen() == 1 )and that didn't work, either.

This is almost exactly the way it's written in the help file. Help?

Offline janua

  • Acquaintance
  • *
  • Posts: 12
    • View Profile
Re: Functionals in room descriptions (attn Crat)
« Reply #1 on: August 09, 2012, 12:28:30 pm »
I'm trying to understand how to write dynamic room descriptions, so I hit the books and wrote this based on the example docs/build/Rooms Part 2: Advanced Room Building.


Code: [Select]
#include <lib.h>
#include ROOMS_H

inherit LIB_ROOM;

string checkDoor(string unused);

void create() {
    room::create();
    SetClimate("outdoors");
    SetAmbientLight(30);
    SetShort("West Gate of Medienne");
    SetNightLong(0);
    SetDayLong(0);
    SetLong( (: checkDoor :) );
    SetItems(([
        ({ "cobble", "cobbles", "cobblestones", "road", "street", "cobbled", "cobbled street", "cobbled road", "cobblestone road", "cobblestone street" }) : "The smoothly worn street is paved with irregular, rounded stones that are tightly fitted together.",
        ({ "wall", "walls", "thick wall", "thick walls" }) : "The wall is made of heavy, gray stone blocks carefully fitted together. It tapers slightly toward the top, where a walkway allows patrols to keep watch over the town.",
      ]));
    SetExits( ([
        "west" : "/domains/medienne/room/med_wgateout",
        "east" : "/domains/medienne/room/main_celm.c",
      ]) );
    SetClimate("temperate");

    SetDoor("west", "/domains/medienne/doors/portcullis_west.c");

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

string checkDoor(string unused){
    string tmp = "The cobbled road intersects with Medienne's thick wall here, and a large, arched opening allows passage out of the town.";
    if( (int)"/domains/Medienne/doors/portcullis_west"->GetOpen()  )
        tmp += " The bottom edge of an open portcullis can be seen in the arch.";
    else tmp += " The opening is blocked by a lowered portcullis.";
    tmp += " A lever is mounted on the wall next to the opening.";
    return tmp;
}



The room description doesn't change when I open the gate. It always reads, "The cobbled road intersects with Medienne's thick wall here, and a large,
arched opening allows passage out of the town. The opening is blocked by a lowered portcullis. A lever is mounted on the wall next to the opening." So the function is working, but the if never evaluates to true.

The way the if statement is written is strange to me, so I tried writing the it like this:
Code: [Select]
if( "/domains/Medienne/doors/portcullis_west"->GetOpen() == 1 )and that didn't work, either.

The room is written almost exactly the way the example is written in the help file. Help?

Offline quixadhal

  • BFF
  • ***
  • Posts: 642
    • View Profile
    • WileyMUD
Re: Functionals in room descriptions (attn Crat)
« Reply #2 on: August 09, 2012, 02:17:25 pm »
Are you on windoze or a unix varient?

If you're on a unix variation, you aren't using the same case for your pathnames.

SetDoor("west", "/domains/medienne/doors/portcullis_west.c");

vs.

if( "/domains/Medienne/doors/portcullis_west"->GetOpen() == 1 )

However, another suggestion is to not put the logic of the changing description in the room, but rather set the open and closed descriptions of the doors to the appropriate lines,and just include door->GetLong() in your room's description, if that's what you want.

Also, it would probably be much nicer to do something like door = GetDoor("west"), and then door->GetOpen(), rather than hard coding the path like that... in case you ever want to copy or move that room somewhere else.

Offline janua

  • Acquaintance
  • *
  • Posts: 12
    • View Profile
Re: Functionals in room descriptions (attn Crat)
« Reply #3 on: August 09, 2012, 09:15:03 pm »
That worked, thanks. Good eye!