Метатабличный / Говнокод #19504 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
while false ~= true do
    -- some code
end

всегда так пишу бесконечные циклы на Lua, ибо в этом есть некий философский смысл)))
код будет выполняться пока ложь не станет истиной...

MegaProger MegaProger, (Updated )

Комментарии (4, +4)

Метатабличный / Говнокод #18346 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
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 года назад назад.

Janycz Janycz, (Updated )

Комментарии (28, +28)

Метатабличный / Говнокод #16820 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
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. Функция проверяет значение переменных в текущей точке пути моба.
Мы перебираем все точки пути и сравниваем с текущей точкой моба, но это не нужно, так как именно текущая точка в функцию и передаётся!

hdkeeper hdkeeper, (Updated )

Комментарии (2, +2)

Метатабличный / Говнокод #16047 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
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-кода от геймдизайнера.

kostoprav kostoprav, (Updated )

Комментарии (3, +3)

Метатабличный / Говнокод #13425 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
['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 файлов.
Нет в жизни счастья.

krypt krypt, (Updated )

Комментарии (8, +8)