Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. function split(pString, pPattern)
  2. local Table = {} -- NOTE: use {n = 0} in Lua-5.0
  3. local fpat = "(.-)" .. pPattern
  4. local last_end = 1
  5. local s, e, cap = pString:find(fpat, 1)
  6. while s do
  7. if s ~= 1 or cap ~= "" then
  8. table.insert(Table,cap)
  9. end
  10. last_end = e+1
  11. s, e, cap = pString:find(fpat, last_end)
  12. end
  13. if last_end <= #pString then
  14. cap = pString:sub(last_end)
  15. table.insert(Table, cap)
  16. end
  17. return Table
  18. end
  19.  
  20. function love.load()
  21. local file = io.open("test.txt", "r");
  22. lines = {}
  23. for line in file:lines() do
  24. table.insert (lines, line);
  25. end
  26. file:close()
  27.  
  28. colors = {}
  29.  
  30. for i=1, #lines do
  31. lines[i] = split(lines[i], " ")
  32. table.remove(lines[i], 1)
  33. for n=1, #lines[i] do
  34. colors[#colors + 1] = lines[i][n]
  35. end
  36. end
  37.  
  38. print(#colors)
  39.  
  40. end
  41.  
  42. function love.draw()
  43. love.graphics.print(#colors, 10, 10)
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement