mouse click fix + doc

This commit is contained in:
p.kosyh 2010-03-15 18:43:23 +00:00
parent 1816dd77ec
commit 93040bdf3e
3 changed files with 32 additions and 7 deletions

View file

@ -186,27 +186,39 @@ And then always use “sw” or some other auxiliary function.
Warning!!! The variables outside any of the following object types: room, object, game, player — never get saved.
From version 0.8.9 you can define a function “isForSave(k)”, which is called to determine whether to save a variable to a savegame file. By default it is defined this way:
From version 0.8.9 you can define a function “isForSave(k)”, which is called to determine whether to save a variable to a savegame file. By default it is defined this way:
<code>
function isForSave(k)
return string.find(k, '_') == 1 or string.match(k,'^%u')
end
</code>
There are two extra parameters for isForSave() (for instead versions > 1.0.0). v -- value, s -- parent table.
Sometimes we need a handler that would do something without showing any description, e.g.:
<code>
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.]];
here()._dynamic_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,
}
r12 = room {
nam = 'room',
_dynamic_dsc = 'I am in the room.',
dsc = function (s) return s._dynamic_dsc end,
obj = {'button'}
}
</code>
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.
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.
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.
Please note the new variable ''_dynamic_dsc'' is used to make a dynamic description in the above example. This is done to ensure new description is saved during the game save. Since the name 'dsc' does not start with underscore or capital letter it will not be saved by default.
===== 6. Inventory =====

View file

@ -186,23 +186,36 @@ apple = obj {
<code>
function isForSave(k)
return string.find(k, '_') == 1 or string.match(k,'^%u')
end
</code>
В версиях instead > 1.0.0 в isForSave() кроме параметра k, передаются v и s. Где v -- значение переменной, s -- родительская таблица, что позволяет гибко настраивать поведение функции сохранения.
Иногда может понадобиться обработчик, который совершал бы некоторое действие, но не выводил никакого описания. Например:
<code>
button = obj {
nam = "кнопка",
dsc = "На стене комнаты видна большая красная {кнопка}.",
act = function (s)
here()._dsc = [[После того как я нажал на кнопку, комната преобразилась. Книжный шкаф куда-то исчез вместе со столом и комодом, а на его месте появился странного вида аппарат.]];
here()._dynamic_dsc = [[После того как я нажал на кнопку, комната преобразилась.
Книжный шкаф куда-то исчез вместе со столом и комодом, а на его месте
появился странного вида аппарат.]];
return true;
end,
}
r12 = room {
nam = 'комната',
_dynamic_dsc = 'Я нахожусь в комнате.',
dsc = function (s) return s._dynamic_dsc end,
obj = {'button'}
}
</code>
В данном случае обработчик `act` нужен для того, чтобы поменять описание комнаты, и не нужно, чтобы чтобы он выводил результат действия. Для отключения результата можно вернуть из обработчика значение true -- это будет означать, что действие успешно выполнено, но не требует дополнительного описания.
В данном случае обработчик `act` нужен для того, чтобы поменять описание комнаты, и не нужно, чтобы чтобы он выводил результат действия. Для отключения результата можно вернуть из обработчика значение true -- это будет означать, что действие успешно выполнено, но не требует дополнительного описания.
Если необходимо показать, что действие невыполнимо, можно вернуть из обработчика `act` значение false или nil. При этом будет отображено описание по умолчанию, заданное с помощью обработчика `game.act`. Обычно описание по умолчанию содержит описание невыполнимых действий.
Обратите внимание, что для создания динамического описания сцены в рассмотренном выше примере использовалось новая переменная _dynamic_dsc. Это сделано для того, чтобы изменённое описание попало в файл сохранения игры. Поскольку имя ''dsc'' не начинается с подчёркивания или заглавной буквы, по умолчанию оно не попадёт в файл сохранения.
===== 6. Инвентарь =====

View file

@ -855,7 +855,7 @@ img_t game_pict_scale(img_t img, int ww, int hh)
float scale1, scale2, scale = 1.0f;
game_pic_w = gfx_img_w(img);
game_pic_h = gfx_img_w(img);
game_pic_h = gfx_img_h(img);
if (game_theme.scale > 1.0f)
theme_img_scale(&img);