Added some lines about act() in docs - supposed by Odyssey

This commit is contained in:
Alexander Yakovlev 2010-01-12 04:00:13 +00:00
parent 71d00ad950
commit 6cf21b2c5d
2 changed files with 33 additions and 1 deletions

View file

@ -176,6 +176,23 @@ apple = obj {
};
\end{verbatim}
Иногда может понадобиться обработчик, который совершал бы некоторое действие, но не выводил никакого описания. Например:
\begin{verbatim}
button = obj {
nam = "кнопка",
dsc = "На стене комнаты видна большая красная {кнопка}.",
act = function (s)
here().dsc = [[После того как я нажал на кнопку, комната преобразилась. Книжный шкаф куда-то исчез вместе со столом и комодом, а на его месте появился странного вида аппарат.]];
return true;
end,
}
\end{verbatim}
В данном случае обработчик \verb/act/ нужен для того, чтобы поменять описание комнаты, и не нужно, чтобы чтобы он выводил результат действия. Для отключения результата можно вернуть из обработчика значение \verb/true/ -- это будет означать, что действие успешно выполнено, но не требует дополнительного описания.
Если необходимо показать, что действие невыполнимо, можно вернуть из обработчика \verb`act` значение \verb/false/ или \verb/nil/. При этом будет отображено описание по умолчанию из \verb`game.act`.
\index{Функции}
Если атрибут или обработчик оформлен как функция, то обычно первый аргумент функции \verb/(s)/ есть сам объект. В данном примере, при показе сцены будет в динамической части сцены будет текст: <<На столе что-то лежит>>. При взаимодействии с <<что-то>>, переменная \verb/_seen/ объекта \verb/apple/ будет установлена в \verb/true/, и мы увидим, что это было яблоко.

View file

@ -80,7 +80,7 @@ Object name “nam” is used when the object gets into the inventory or to addr
“dsc” is an object descriptor. It will be shown in the dynamic part of the scene. Curly brackets indicate the text fragment which will be a link anchor in the graphic interpreter.
“act” is a handler, called when the player uses a scene object. It has to return a text line, which will become a part of the scene events.
“act” is a handler, called when the player uses a scene object. It has to return a text line, which will become a part of the scene events, or a boolean value (see chapter 5)
WARNING: in the lua namespace some objects (tables) already exist. For example “table”, “io”, “string”... Be careful when creating objects. In the example above “tabl” is used instead of “table”.
@ -192,6 +192,21 @@ function isForSave(k)
return string.find(k, '_') == 1 or string.match(k,'^%u')
}}}
Sometimes we need a handler that would do something without showing any description, e.g.:
{{{
button = obj {
nam = "button",
dsc = "There is a big red {button} on the room wall.",
act = function (s)
here().dsc = [[The room transformed after I pressed the button. The book-case disappeared along with the table and the chest, and a strange looking device took its place.]];
return true;
end,
}
}}}
In this case `act` handler is used to change room description but it is not supposed to add any description of its own. To achieve this we need to return true from the handler. It means the action is done successfully but does not require to diplay any additional description.
If you need to show some action is impossible, you can return false or nil from its `act` handler. In this case default description will be shown for this action. Default actions can be set via game.act handler and are generally used for description of impossible actions.
== 6. Inventory ==