- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
a = {}
a[{}] = 100500
local store
for i, k in pairs(a) do
print(i,k) --table, 100500
store = i
end
print(a[{}]) --nil
print(a[store]) --100500
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
a = {}
a[{}] = 100500
local store
for i, k in pairs(a) do
print(i,k) --table, 100500
store = i
end
print(a[{}]) --nil
print(a[store]) --100500
0
math.randomseed(math.random(1,100))
0
a = {}
table.insert(a,a)
a[1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][21312] = 5
a[1][1][1][1][1][1][1][1][1][1] = 1
print(a[1], a[21312]) -- Вывод: 1, 5
0
a = {try = function() if a then print("\"a\" BE!") else print("\"a\" not BE!") end end}
a.try()
Проверка самого себя на существование, а вдруг он чья та иллюзия?!
0
while false ~= true do
-- some code
end
всегда так пишу бесконечные циклы на Lua, ибо в этом есть некий философский смысл)))
код будет выполняться пока ложь не станет истиной...
0
local sol_lines = {}
local i = 1; local j = 0;
while (i <= solution:len()) do
local begin_pos = i
while(i <= solution:len() and solution:sub(i, i) ~= '\n') do
i = i + 1
end
if i > solution:len() then
i = solution:len()
end
local cur_line = solution:sub(begin_pos, i)
sol_lines[j] = trim(cur_line)
i = i + 1
j = j + 1
end
Lua
Как я разбивал строку на отдельные линии. Вместо того, чтобы использовать string.find(s, "\n", i + 1). Так я писал код 0.027397 года назад назад.
0
function SAEController:GetPointVariableValue(WayNet,CurPoint)
local waypointVars = {};
for i = 0, WayNet:GetPointsCount() - 1 do
local Link = WayNet:GetPoint(i);
local PlaySound1 = Link:GetVariableValue("PlaySound1");
local PlaySound2 = Link:GetVariableValue("PlaySound2");
local PlaySound3 = Link:GetVariableValue("PlaySound3");
local Effect1 = Link:GetVariableValue("Effect1");
local Effect2 = Link:GetVariableValue("Effect2");
local Effect3 = Link:GetVariableValue("Effect3");
if PlaySound1 and CurPoint == Link then
waypointVars.PlaySound1 = PlaySound1;
end;
if PlaySound2 and CurPoint == Link then
waypointVars.PlaySound2 = PlaySound2;
end;
if PlaySound3 and CurPoint == Link then
waypointVars.PlaySound3 = PlaySound3;
end;
if Effect1 and CurPoint == Link then
waypointVars.Effect1 = Effect1;
end;
if Effect2 and CurPoint == Link then
waypointVars.Effect2 = Effect2;
end;
if Effect3 and CurPoint == Link then
waypointVars.Effect3 = Effect3;
end;
end;
return waypointVars;
end;
Кусок игровой логики на Lua. Функция проверяет значение переменных в текущей точке пути моба.
Мы перебираем все точки пути и сравниваем с текущей точкой моба, но это не нужно, так как именно текущая точка в функцию и передаётся!
0
c1 = true
c2 = true
c3 = true
c4 = true
c5 = true
c6 = true
c7 = true
c8 = true
c9 = true
c10 = true
c11 = true
c12 = true
c13 = true
next = true
function goForward()
c1 = c2
c2 = c3
c3 = c4
c4 = c5
c5 = c6
c6 = c7
c7 = c8
c8 = c9
c9 = c10
c10 = c11
c11 = c12
c12 = c13
c13 = next
end
Немножко Lua-кода от геймдизайнера.
0
if hiGrifters.year > 2014 or hiGrifters.month > 1 or hiGrifters.day == nil then
os.exit(0)
end
Защита вшитая в библиотеку на lua - проверять условия с датами мы не умеем
0
['run'] = function(num, skipt)
if num > 0 and num <= table.maxn(_G.levels_code.list) then
if tbl_save._.options.tutorial then
if ((_G.levels_code.list[num][2] == 1 and _G.levels_code.list[num][1] == 1) or (_G.levels_code.list[num][2] == 1 and _G.levels_code.list[num][1] == 0)) and not skipt then
game.Mission.instance():runLevel(fld.levelTutorial, 1)
mawidgets._.hud.action.set_lvl(fld.levelTutorial, 1)
mawidgets._.tips_widget.action.set('tutorial')
_G.widget_type = 'tutorial';
mawidgets._.tutorial.texts.tutorial_text:setText("Tutorial1")
elseif ((_G.levels_code.list[num][2] == 2 and _G.levels_code.list[num][1] == 1) or (_G.levels_code.list[num][2] == 5 and _G.levels_code.list[num][1] == 0)) and not skipt then
game.Mission.instance():runLevel(fld.levelTutorial, 2)
mawidgets._.hud.action.set_lvl(fld.levelTutorial, 2)
mawidgets._.tips_widget.action.set('tutorial')
_G.widget_type = 'tutorial';
mawidgets._.tutorial.texts.tutorial_text:setText("Tutorial2")
elseif ((_G.levels_code.list[num][2] == 3 and _G.levels_code.list[num][1] == 1) or (_G.levels_code.list[num][2] == 11 and _G.levels_code.list[num][1] == 0)) and not skipt then
game.Mission.instance():runLevel(fld.levelTutorial, 3)
mawidgets._.hud.action.set_lvl(fld.levelTutorial, 3)
mawidgets._.tips_widget.action.set('tutorial')
_G.widget_type = 'tutorial';
mawidgets._.tutorial.texts.tutorial_text:setText("Tutorial3")
elseif ((_G.levels_code.list[num][2] == 5 and _G.levels_code.list[num][1] == 1) or (_G.levels_code.list[num][2] == 15 and _G.levels_code.list[num][1] == 0)) and not skipt then
game.Mission.instance():runLevel(fld.levelTutorial, 4)
mawidgets._.hud.action.set_lvl(fld.levelTutorial, 4)
mawidgets._.tips_widget.action.set('tutorial')
_G.widget_type = 'tutorial';
mawidgets._.tutorial.texts.tutorial_text:setText("Tutorial4")
elseif ((_G.levels_code.list[num][2] == 6 and _G.levels_code.list[num][1] == 1) or (_G.levels_code.list[num][2] == 16 and _G.levels_code.list[num][1] == 0)) and not skipt then
game.Mission.instance():runLevel(fld.levelTutorial, 5)
mawidgets._.hud.action.set_lvl(fld.levelTutorial, 5)
mawidgets._.tips_widget.action.set('tutorial')
_G.widget_type = 'tutorial';
mawidgets._.tutorial.texts.tutorial_text:setText("Tutorial5")
else
mawidgets._.tips_widget.action.set('clear')
_G.widget_type = 0;
mawidgets._.tutorial.action.hide()
if _G.levels_code.list[num][1] == 2 and tbl_save._.options.tutorial_bonus then
mawidgets._.tutorial.texts.tutorial_text:setText("Tutorial6")
end
game.Mission.instance():runLevel(_G.levels_code.list[num][1], _G.levels_code.list[num][2])
mawidgets._.hud.action.set_lvl(_G.levels_code.list[num][1], _G.levels_code.list[num][2])
end
else
mawidgets._.tips_widget.action.set('clear')
tbl_save._.options.tutorial_bonus = false
data.WriteDataInSlot(tbl_save._)
mawidgets._.tutorial.action.hide()
game.Mission.instance():runLevel(_G.levels_code.list[num][1], _G.levels_code.list[num][2])
mawidgets._.hud.action.set_lvl(_G.levels_code.list[num][1], _G.levels_code.list[num][2])
end
else print('_G.levels_code.run -> bad level num: ', num) end
end;
Игра - головоломка, язык этого гк - Lua, в проекте - ~ 26 000 файлов.
Нет в жизни счастья.