饥荒联机版自制MOD教程 自己怎么制作MOD 准备工作( 四 )


my_var = "hello"
短路求值/Minimal evaluation
由于Lua内核是基于C语言编写的,支持短路求值自然不足为奇 。
所谓短路求值,即在以下Lua代码
if condition_A and condition_B and condition_C then
中,首先计算 condition_A 的真值,若 condition_A 为假(false),则跳出;否则依次计算下一个布尔表达式的真值,直到出现假或者全部表达式都计算完毕为止 。
表/Table
Lua的设计者在其语法中引入了表的概念,用以表示中的数组(Array)和图(Map)两种数据结构 。
1、创建一个表
你可以创建一个以字符串为键(Key)的表,即:
my_map = { apple = 5, banana = 10, melon = 9 }
或者一个类似数组的表,即:
my_array = { "Tom", "Jack", "Peter" }
2、修改表中的数据
如果你的表是以字符串为键的,那么你可以:
my_map.apple = 15
或者
my_map["apple"] = 17
如果你的表示以数字为键的,那么你可以:
my_array[1] = "Tompson"
请注意,Lua中以数字为键的表跟C/C++中数组不同,也就是 my_array[0] 的值是 nil 。
表的遍历
以字符串为键的表通过以下语法进行遍历:
for k, v in pairs(my_map) do
而以数字为键的表则是:
for i, v in ipairs(my_array) do
控制结构
选择
if exp then
block
elseif exp then
block
else
block
end
当型循环
while exp do
block
end
直到型循环
repeat
block
until exp
从循环中跳出
在循环结构中使用 return 和 break 可以跳出 。

参考资料
与Lua有关的:
Lua 5.1 Reference:http://www.lua.org/manual/5.1/
Lua 5.0 Reference:http://www.lua.org/ftp/refman-5.0.pdf
Pre-compiled Lua libraries and executables:http://luabinaries.sourceforge.net/download.html
与DST有关的:
[Guide] Getting started with modding DST:http://forums.kleientertainment.com/topic/47353-guide-getting-started-with-modding-dst-and-some-general-tips-for-ds-as-well/
Getting Started: Guides, Tutorials and Examples:http://forums.kleientertainment.com/topic/28021-getting-started-guides-tutorials-and-examples/
Don't Starve Mods:http://dontstarve.wikia.com/wiki/Mods
Unofficial API Reference:http://dontstarveapi.com/
[Tutorial] Using Extended Sample Character Template - Tutorials & Guides - Klei Entertainment Forums:http://forums.kleientertainment.com/topic/46849-tutorial-using-extended-sample-character-template/
Matt's Tools! - Modding Tools, Tutorials & Examples - Klei Entertainment:http://forums.kleientertainment.com/files/file/73-matts-tools/
Better Crashes (RoG compatible) - Game Modifications - Klei Entertainment Forums:http://forums.kleientertainment.com/files/file/514-better-crashes-rog-compatible/

推荐阅读