Parameter | Type | Description |
---|---|---|
PLAYER | PLAYER | The player to check from. |
OBJECT | OBJECT | The object to test. |
VALUE(BOOLEAN) | TRUE if the provided player can access the provided object, or FALSE if not. |
This function performs a check to see if a player can access a specific object, given its current state (player's current room, object's current owner, etc.). These are the same checks for testing what objects can be "seen" when a command is entered into the interpreter.
action modal a_go named "go" uses modes "north", "south", "west", "east";
action transitive a_examine named "look at", "examine", "x";
action general a_quit named "quit";
action general a_look; // queued every action.
action general a_objectcheck; // queued every action.
// Room Prototypes
room r_northroom;
room r_southroom;
object o_redball named "red ball", "ball" uses determiners "the"
{
onAction(a_examine)
{
textln("It's a red ball.");
}
onRoomBrowse()
{
textln("A red ball is here.");
}
}
object o_blueball named "blue ball", "ball" uses determiners "the"
{
onAction(a_examine)
{
textln("It's a blue ball.");
}
onRoomBrowse()
{
textln("A blue ball is here.");
}
}
object o_greenball named "green ball", "ball" uses determiners "the"
{
onAction(a_examine)
{
textln("It's a green ball.");
}
onPlayerBrowse()
{
textln("A green ball.");
}
}
extend room r_northroom
{
onAction(a_look)
{
textln("You are in the north room.");
textln("The way out is south.");
browse(room);
}
onModalAction(a_go, "south")
{
setRoom(player, r_southroom);
}
}
extend room r_southroom
{
onAction(a_look)
{
textln("You are in the south room.");
textln("The way out is north.");
browse(room);
}
onModalAction(a_go, "north")
{
setRoom(player, r_northroom);
}
}
player p_main
{
onIncompleteCommand(a_go)
{
textln("GO where? (Need a compass direction)");
}
onUnhandledAction(a_go)
{
textln("Can't go that way.");
}
}
world
{
init()
{
setRoom(p_main, r_southroom);
setPlayer(p_main); // from this moment on, this is the "player" keyword.
giveObject(p_main, o_greenball);
giveObject(world, o_redball);
giveObject(r_northroom, o_blueball);
}
start()
{
textln("Type \"quit\" to quit, \"go\" and a compass direction to move between rooms.");
textln("You have a green ball.");
queue a_look;
queue a_objectcheck;
}
onAction(a_objectcheck)
{
if (playerCanAccessObject(player, o_greenball))
textln("You can access the green ball.");
else
textln("You can NOT access the green ball.");
if (playerCanAccessObject(player, o_redball))
textln("You can access the red ball.");
else
textln("You can NOT access the red ball.");
if (playerCanAccessObject(player, o_blueball))
textln("You can access the blue ball.");
else
textln("You can NOT access the blue ball.");
}
onAction(a_quit)
{
quit;
}
afterSuccessfulCommand()
{
queue a_look;
queue a_objectcheck;
}
}
"Object Accessibility" from this function call is determined by the player and object state at the moment that the function is executed - not before, not after. If the provided player is not in any room or the provided object has no owner, the object is never accessible from that player.
An object without any names assigned to it, and thus not accessible/parse-able via an interpreted command, can still be considered accessible by this function. An anonymous object is still a valid object.