LPMuds.net

Lib Discussion => Dead Souls Support => Topic started by: brainfrz on January 19, 2009, 01:59:42 pm

Title: Parse Error in Hiding
Post by: brainfrz on January 19, 2009, 01:59:42 pm
For some strange reason, line 10 is coming up with a parse error. What I'm trying to do is make it so a set of rooms can inherit this one and have the privacy field code. Here's the file:
Code: [Select]
#define PRIV_FILE  __DIR__"allow.list"

#include <rooms.h>

inherit LIB_ROOM;

int privacy = 0;
string *trust = explode(read_file(PRIV_FILE), "\n");
for( int i = 0; i < sizeof(trust); i++ )
    trust[i] = lower_case(trust[i]);
string owner = trust[0];

void create_workroom() { }
void init_workroom()   { }
string SetPrivacy(int i);
string SetDesc(string str);
string GetDesc();

string DescPrivacy()
{
    if( privacy )
        return desc + "\n\
%^YELLOW%^The walls seem to be encased in a yellowish shield.%^RESET%^";
    return desc;
}
string SetDesc( string str )
{
    return desc = str;
}
string GetDesc()
{
    return desc;
}

static void create()
{
    room::create();
    create_workroom();
    SetDesc(this_object()->GetDesc())
    SetLong((: DescPrivacy :));
}
void init()
{
    ::init();
    init_workroom();
    add_action("mod_privacy", ({ "privacy", "priv" }));
    add_action("eventAllow",  "allow");
    add_action("eventReject", "reject");
}

int CanReceive( object sneak )
{
    int ret;
    object *living_stack;
    if( !privacy )
        return ::CanReceive(sneak);
    living_stack = get_livings(sneak);
    if( !living_stack || !arrayp(living_stack) )
        living_stack = ({ sneak });
    foreach( object ob in living_stack )
    {
        if( !archp(ob) && member_array(ob->GetKeyName(), trust) == -1 )
        {
            message("info", "You bounce off the privacy field.", ob);
            message("info", ob->GetName()+" bounced off the privacy field.",
                    this_object());
            if( !environment(ob) )
                ob->eventMoveLiving(ROOM_START);
            return 0;
        }
    }
    ret = ::CanReceive(sneak);
    if( ret )
        tell_room(this_object(), "\n\nPRIVACY WARNING: "+identify(sneak)+
                " has entered the room.\n\n", sneak);
    return ret;
}

int set_privacy( int i )
{
    object *npcs = filter(deep_inventory(this_object()),
            (: living($1) && !interactive($1) :));
    privacy = i;
    SetProperty("no peer", i);
    if( sizeof(npcs) )
    {
        foreach( object npc in npcs )
        {
            tell_room(this_object(), "Ejecting "+identify(npc), npc);
            npc->eventMove(ROOM_FURNACE);
        }
    }
    SetLong((: DescPrivacy :));
    return privacy;
}

int mod_privacy( string str )
{
    if( !archp(this_player()) &&
            this_player()->GetKeyName() != lower_case(owner) )
    {
        write("You close your eyes, but nothing changes.");
        say(this_player()->GetName()+" is trying to muck around with the privacy field system.");
        return 1;
    }
    if( !str || (str != "off" && str != "on") )
    {
        if( privacy )
            str = "off";
        else
            str = "on";
    }
    if( str == "on" )
    {
        set_privacy(1);
        write("You close your eyes, and the walls shimmer briefly.");
        say(this_player()->GetName()+" closes "+possessive(this_player())+
            " eyes, and the walls shimmer briefly.");
        return 1;
    }
    if( str == "off" )
    {
        set_privacy(0);
        write("You close your eyes, and a gentle draft passes through the room.");
        say(this_player()->GetName()+" closes "+possessive(this_player())+
            " eyes, and a gentle draft passes through the room.");
        return 1;
    }
}
Title: Re: Parse Error in Hiding
Post by: brainfrz on January 19, 2009, 02:10:04 pm
I was told that the problem was in the for-loop, so I moved it down to create(). However, I'm still getting a parse error, but this time on line 42.
Code: [Select]
#define PRIV_FILE  __DIR__"allow.list"

#include <rooms.h>

inherit LIB_ROOM;

int privacy = 0;
string *trust = explode(read_file(PRIV_FILE), "\n");
string owner, desc = "";

void create_workroom() { }
void init_workroom()   { }
string SetPrivacy(int i);
string SetDesc(string str);
string GetDesc();

string DescPrivacy()
{
    if( privacy )
        return desc + "\n\
%^YELLOW%^The walls seem to be encased in a yellowish shield.%^RESET%^";
    return desc;
}
string SetDesc( string str )
{
    return desc = str;
}
string GetDesc()
{
    return desc;
}

static void create()
{
    int sizeTrust = sizeof(trust);
    for( int i = 0; i < sizeTrust; i++ )
        trust[i] = lower_case(trust[i]);
    owner = trust[0];
    room::create();
    create_workroom();
    SetDesc(this_object()->GetDesc())
    [b]SetLong((: DescPrivacy :));[/b]
}
Isn't this EXACTLY the same as in the standard workroom?
Title: Re: Parse Error in Hiding
Post by: Raudhrskal on January 19, 2009, 02:17:52 pm
MAN! Not the for-loop, the CODE.
Only thing you can assign using '=' at the top-level variable declarations are CONSTANTS.

You're doing a func call to read_file().

and that must be done in create() (or any other function, but, you're trying to initialize, so, in create())

Make the top decl just "string *trust;" and put "trust = whateveryouneed();" in create() before for(). Understood?
Title: Re: Parse Error in Hiding
Post by: daelaskai on January 19, 2009, 07:23:04 pm
Brainfrz,

If you would like to take a look at a privacy room for a workroom, you should
look me up at The Void.  I can show you mine if you are interested.  It's
a bunch more complex than what you're doing, but it's also highly customizable.

Daelas