Advertisement
HugoBDesigner

customvariables

Jul 30th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.38 KB | None | 0 0
  1.     if variablesupdate then
  2.         if love.filesystem.exists("mappacks/" .. mappack .. "/customvariables.txt") then
  3.             local v = love.filesystem.read("mappacks/" .. mappack .. "/customvariables.txt")
  4.             local v1 = v:split("\n")
  5.             for i = 1, #v1 do
  6.                 local v2 = v1:split(" = ")
  7.                 local v2splited = v2[2]:split(" --")
  8.                 local vv = v2splited[1]
  9.                 local vartype = ""
  10.                 local vartypevalues = {}
  11.                 local numbers = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
  12.                 local letters = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}
  13.                 local firstchar = string.sub(vv, 1)
  14.                 local secondchar = string.sub(vv, 2)
  15.                 for i = 1, #numbers do
  16.                     if firstchar == numbers[i] then
  17.                         vartype = "numeric"
  18.                     end
  19.                 end
  20.                 if firstchar == "{" then
  21.                     vartype = "table"
  22.                     if secondchar == "\"" then
  23.                         vartype = vartype .. "strings"
  24.                     else
  25.                         for i = 1, #letters do
  26.                             if secondchar == letters[i] then
  27.                                 vartype = vartype .. "alphabetic"
  28.                             end
  29.                         end
  30.                         for i = 1, #numbers do
  31.                             if secondchar == numbers[i] then
  32.                                 vartype = vartype .. "numeric"
  33.                         end
  34.                     end
  35.                 end
  36.  
  37.                 if string.sub(vartype, 1, 5) == "table" then
  38.                     local v3 = vv:split(", ")
  39.                     for i = 1, #v3 do
  40.                         if vartype == "tablenumeric" then
  41.                             vartypevalues[v3[i]] = tonumber(v3[i])
  42.                         elseif vartype == "tablealphabetic" then
  43.                             vartypevalues[v3[i]] = v3[i]
  44.                         else
  45.                             vartypevalues[v3[i]] = _G[v3[i]]
  46.                         end
  47.                     end
  48.                 end
  49.  
  50.                 if vartype == "numeric" then
  51.                     _G[v2[1]] = tonumber(vv)
  52.                 elseif vartype == "alphabetic" then
  53.                     _G[v2[1]] = vv
  54.                 elseif string.sub(vartype, 1, 5) == "table" then
  55.                     _G[v2[1]] = vartypevalues
  56.                 end
  57.             end
  58.         else
  59.             local v = love.filesystem.read("regularvariables.txt")
  60.             local v1 = v:split("\n")
  61.             for i = 1, #v1 do
  62.                 local v2 = v1:split(" = ")
  63.                 local v2splited = v2[2]:split(" --")
  64.                 local vv = v2splited[1]
  65.                 local vartype = ""
  66.                 local vartypevalues = {}
  67.                 local numbers = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
  68.                 local letters = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}
  69.                 local firstchar = string.sub(vv, 1)
  70.                 local secondchar = string.sub(vv, 2)
  71.                 for i = 1, #numbers do
  72.                     if firstchar == numbers[i] then
  73.                         vartype = "numeric"
  74.                     end
  75.                 end
  76.                 if firstchar == "{" then
  77.                     vartype = "table"
  78.                     if secondchar == "\"" then
  79.                         vartype = vartype .. "strings"
  80.                     else
  81.                         for i = 1, #letters do
  82.                             if secondchar == letters[i] then
  83.                                 vartype = vartype .. "alphabetic"
  84.                             end
  85.                         end
  86.                         for i = 1, #numbers do
  87.                             if secondchar == numbers[i] then
  88.                                 vartype = vartype .. "numeric"
  89.                         end
  90.                     end
  91.                 end
  92.  
  93.                 if string.sub(vartype, 1, 5) == "table" then
  94.                     local v3 = vv:split(", ")
  95.                     for i = 1, #v3 do
  96.                         if vartype == "tablenumeric" then
  97.                             vartypevalues[v3[i]] = tonumber(v3[i])
  98.                         elseif vartype == "tablealphabetic" then
  99.                             vartypevalues[v3[i]] = v3[i]
  100.                         else
  101.                             vartypevalues[v3[i]] = _G[v3[i]]
  102.                         end
  103.                     end
  104.                 end
  105.  
  106.                 if vartype == "numeric" then
  107.                     _G[v2[1]] = tonumber(vv)
  108.                 elseif vartype == "alphabetic" then
  109.                     _G[v2[1]] = vv
  110.                 elseif string.sub(vartype, 1, 5) == "table" then
  111.                     _G[v2[1]] = vartypevalues
  112.                 end
  113.             end
  114.         end
  115.         variablesupdate = false
  116.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement