doc update
This commit is contained in:
parent
85a61f9a9b
commit
016a4fb6aa
|
@ -198,7 +198,7 @@ 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()._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,
|
||||
}
|
||||
|
@ -837,13 +837,26 @@ pl.Life = 10;
|
|||
pl.Power = 10;
|
||||
|
||||
status = obj {
|
||||
nam = 'Life: '..pl.Life..',Power: '..pl.Power,
|
||||
nam = function(s)
|
||||
return 'Life: '..pl.Life..',Power: '..pl.Power
|
||||
end
|
||||
};
|
||||
inv():add('status');
|
||||
status.object_type = false
|
||||
</code>
|
||||
|
||||
From version 0.9.1 you can use stat constructor for status.
|
||||
<code>
|
||||
pl.Life = 10;
|
||||
pl.Power = 10;
|
||||
|
||||
status = stat {
|
||||
nam = function(s)
|
||||
return 'Life: '..pl.Life..',Power: '..pl.Power
|
||||
end
|
||||
};
|
||||
inv():add('status');
|
||||
</code>
|
||||
|
||||
==== “goto” from the “exit” handler ====
|
||||
|
||||
|
@ -1022,9 +1035,9 @@ main = room {
|
|||
</code>
|
||||
|
||||
==== Keyboard ====
|
||||
Since the version 1.1.0 ''instead'' supports the keyboard input. (Only for sdl version.) Use the ''input'' object for this.
|
||||
Since version 1.1.0 ''instead'' supports keyboard input (works with SDL version only). This can be done using ''input'' object.
|
||||
|
||||
input.key(s, pressed, key) -- keyboard handler; pressed -- press or release action; key -- symbolic name of the key;
|
||||
input.key(s, pressed, key) -- keyboard handler; pressed -- press or release event; key -- symbolic name of the key;
|
||||
|
||||
Handler can return a ''stead'' interface command. In this case the interpreter doesn't handle a key.
|
||||
For example:
|
||||
|
@ -1048,13 +1061,72 @@ main = room {
|
|||
force_dsc = true,
|
||||
nam = 'Keyboard',
|
||||
dsc = function(s)
|
||||
return 'Exmaple: '..tostring(s._txt);
|
||||
return 'Example: '..tostring(s._txt);
|
||||
end
|
||||
};
|
||||
</code>
|
||||
|
||||
==== Mouse ====
|
||||
Since version 1.1.5 ''instead'' supports mouse click handling (works with SDL version only). This can be done using ''input'' object.
|
||||
|
||||
input.click(s, pressed, mb, x, y, px, py) -- mouse click handler; pressed -- press or release event. mb -- mouse button index (1 is left button), x and y -- mouse cursor coordinates relative to upper left corner of the window. px and py parameters exist if a picture have been clicked, they contain mouse cursor coordinates relative to upper left corner of this picture.
|
||||
|
||||
|
||||
Handler can return a ''stead'' interface command. In this case the interpreter doesn't handle a key.
|
||||
For example:
|
||||
<code>
|
||||
input.click = function(s, press, mb, x, y, px, py)
|
||||
if press and px then
|
||||
click.x = px;
|
||||
click.y = py;
|
||||
click:enable();
|
||||
return "look"
|
||||
end
|
||||
end
|
||||
|
||||
click = obj {
|
||||
nam = 'click',
|
||||
x = 0,
|
||||
y = 0,
|
||||
dsc = function(s)
|
||||
return "You clicked a picture at "..s.x..','..s.y..'.';
|
||||
end
|
||||
}:disable();
|
||||
|
||||
main = room {
|
||||
nam = 'test',
|
||||
pic ='picture.png',
|
||||
dsc = 'Example.',
|
||||
obj = { 'click' },
|
||||
};
|
||||
</code>
|
||||
|
||||
Here is an example of a code layer that implements calling ''click'' method in the current room once the picture is clicked:
|
||||
<code>
|
||||
input.click = function(s, press, mb, x, y, px, py)
|
||||
if press and px then
|
||||
return "click "..px..','..py;
|
||||
end
|
||||
end
|
||||
|
||||
game.action = function(s, cmd, x, y)
|
||||
if cmd == 'click' then
|
||||
return call(here(), 'click', x, y);
|
||||
end
|
||||
end
|
||||
----------------------------------------------------------------------
|
||||
main = room {
|
||||
nam = 'test',
|
||||
pic ='picture.png',
|
||||
dsc = 'Example.',
|
||||
click = function(s, x, y)
|
||||
return "You clicked a picture at "..x..','..y..'.';
|
||||
end
|
||||
};
|
||||
</code>
|
||||
|
||||
==== Dynamic object creation ====
|
||||
You can use ''new'' и ''delete'' functions to create and remove dynamic objects. An example follows.
|
||||
You can use ''new'' and ''delete'' functions to create and remove dynamic objects. An example follows.
|
||||
|
||||
<code>
|
||||
new ("obj { nam = 'test', act = 'test' }")
|
||||
|
|
|
@ -194,7 +194,7 @@ button = obj {
|
|||
nam = "кнопка",
|
||||
dsc = "На стене комнаты видна большая красная {кнопка}.",
|
||||
act = function (s)
|
||||
here().dsc = [[После того как я нажал на кнопку, комната преобразилась. Книжный шкаф куда-то исчез вместе со столом и комодом, а на его месте появился странного вида аппарат.]];
|
||||
here()._dsc = [[После того как я нажал на кнопку, комната преобразилась. Книжный шкаф куда-то исчез вместе со столом и комодом, а на его месте появился странного вида аппарат.]];
|
||||
return true;
|
||||
end,
|
||||
}
|
||||
|
@ -821,13 +821,26 @@ pl.Life = 10;
|
|||
pl.Power = 10;
|
||||
|
||||
status = obj {
|
||||
nam = 'Жизнь: '..pl.Life..',Сила: '..pl.Power,
|
||||
nam = function(s)
|
||||
return 'Жизнь: '..pl.Life..',Сила: '..pl.Power
|
||||
end
|
||||
};
|
||||
inv():add('status');
|
||||
status.object_type = false
|
||||
</code>
|
||||
|
||||
Начиная с версии 0.9.1 вы можете использовать конструктор stat для создания статуса.
|
||||
<code>
|
||||
pl.Life = 10;
|
||||
pl.Power = 10;
|
||||
|
||||
status = stat {
|
||||
nam = function(s)
|
||||
return 'Жизнь: '..pl.Life..',Сила: '..pl.Power
|
||||
end
|
||||
};
|
||||
inv():add('status');
|
||||
</code>
|
||||
|
||||
==== goto из обработчика exit ===
|
||||
|
||||
|
@ -1004,7 +1017,7 @@ main = room {
|
|||
</code>
|
||||
|
||||
==== Клавиатура ====
|
||||
Начиная с версии 1.1.0 в instead появлилась возможность анализировать ввод с клавиатуры. (Только в графической версии интерпретатора.) Для этого используется объект input.
|
||||
Начиная с версии 1.1.0 в instead появилась возможность анализировать ввод с клавиатуры (только в графической версии интерпретатора). Для этого используется объект input.
|
||||
|
||||
input.key(s, pressed, key) -- обработчик клавиатуры; pressed -- нажатие или отжатие. key -- символьное имя клавиши;
|
||||
|
||||
|
@ -1035,6 +1048,65 @@ main = room {
|
|||
};
|
||||
</code>
|
||||
|
||||
==== Мышь ====
|
||||
Начиная с версии 1.1.5 в instead появилась возможность анализировать события мыши. (Только в графической версии интерпретатора.) Для этого используется объект input.
|
||||
|
||||
input.click(s, pressed, mb, x, y, px, py) -- обработчик клика мыши; pressed -- нажатие или отжатие. mb -- номер кнопки (1 - левая), x и y -- координаты клика относительно левого верхнего угла. px и py присутствуют, если клик произошел в области картинки сцены и содержит координаты клика относительно левого верхнего угла картинки.
|
||||
|
||||
Обработчик может вернуть команду интерфейса stead, в этом случае клик не будет обработана интерпретатором.
|
||||
|
||||
Например:
|
||||
<code>
|
||||
input.click = function(s, press, mb, x, y, px, py)
|
||||
if press and px then
|
||||
click.x = px;
|
||||
click.y = py;
|
||||
click:enable();
|
||||
return "look"
|
||||
end
|
||||
end
|
||||
|
||||
click = obj {
|
||||
nam = 'клик',
|
||||
x = 0,
|
||||
y = 0,
|
||||
dsc = function(s)
|
||||
return "Вы кликнули по картинке в позиции: "..s.x..','..s.y..'.';
|
||||
end
|
||||
}:disable();
|
||||
|
||||
main = room {
|
||||
nam = 'test',
|
||||
pic ='picture.png',
|
||||
dsc = 'Демонстрация.',
|
||||
obj = { 'click' },
|
||||
};
|
||||
</code>
|
||||
|
||||
Пример прослойки, которая реализует вызов метода click в текущей комнате при клике на картинку:
|
||||
<code>
|
||||
input.click = function(s, press, mb, x, y, px, py)
|
||||
if press and px then
|
||||
return "click "..px..','..py;
|
||||
end
|
||||
end
|
||||
|
||||
game.action = function(s, cmd, x, y)
|
||||
if cmd == 'click' then
|
||||
return call(here(), 'click', x, y);
|
||||
end
|
||||
end
|
||||
----------------------------------------------------------------------
|
||||
main = room {
|
||||
nam = 'test',
|
||||
pic ='picture.png',
|
||||
dsc = 'Демонстрация.',
|
||||
click = function(s, x, y)
|
||||
return "Вы кликнули по картинке в позиции: "..x..','..y..'.';
|
||||
end
|
||||
};
|
||||
</code>
|
||||
|
||||
==== Динамическое создание объектов ====
|
||||
Вы можете использовать функции new и delete для создания и удаления динамических объектов. Примеры:
|
||||
|
||||
|
|
Reference in a new issue