日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

饑荒聯(lián)機版自制MOD教程 自己怎么制作MOD 準備工作( 四 )


my_var = "hello"
短路求值/Minimal evaluation
由于Lua內(nèi)核是基于C語言編寫的,支持短路求值自然不足為奇 。
所謂短路求值,即在以下Lua代碼
if condition_A and condition_B and condition_C then
中,首先計算 condition_A 的真值,若 condition_A 為假(false),則跳出;否則依次計算下一個布爾表達式的真值,直到出現(xiàn)假或者全部表達式都計算完畢為止 。
表/Table
Lua的設(shè)計者在其語法中引入了表的概念,用以表示中的數(shù)組(Array)和圖(Map)兩種數(shù)據(jù)結(jié)構(gòu) 。
1、創(chuàng)建一個表
你可以創(chuàng)建一個以字符串為鍵(Key)的表,即:
my_map = { apple = 5, banana = 10, melon = 9 }
或者一個類似數(shù)組的表,即:
my_array = { "Tom", "Jack", "Peter" }
2、修改表中的數(shù)據(jù)
如果你的表是以字符串為鍵的,那么你可以:
my_map.apple = 15
或者
my_map["apple"] = 17
如果你的表示以數(shù)字為鍵的,那么你可以:
my_array[1] = "Tompson"
請注意,Lua中以數(shù)字為鍵的表跟C/C++中數(shù)組不同,也就是 my_array[0] 的值是 nil 。
表的遍歷
以字符串為鍵的表通過以下語法進行遍歷:
for k, v in pairs(my_map) do
而以數(shù)字為鍵的表則是:
for i, v in ipairs(my_array) do
控制結(jié)構(gòu)
選擇
if exp then
block
elseif exp then
block
else
block
end
當(dāng)型循環(huán)
while exp do
block
end
直到型循環(huán)
repeat
block
until exp
從循環(huán)中跳出
在循環(huán)結(jié)構(gòu)中使用 return 和 break 可以跳出 。

參考資料
與Lua有關(guān)的:
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有關(guān)的:
[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/

推薦閱讀