This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
cdel's profile picture

For input string "1k"

Started by cdel, 10 December 2014 - 09:56 AM
cdel #1
Posted 10 December 2014 - 10:56 AM
I was trying to finish off the draw function for my basic Engine Zen, but I encountered an error. I am unsure how to fix this error due to the fact that I haven't ever encountered it before. I want it to cycle through all the objects, if an object has an image attribute I want it to display it.

Code

local zen = { }
zen.build = 1
zen.objects = { }
zen.graphics = { }
local width, height = term.getSize()
local err = function(text)
  print("Zen: "..text)
  return
end
zen.new = function(name)
  if zen.objects[name] then
    err("Object Already Exists")
  else
    zen.objects[name] = { }
  end
end
zen.add = function(name, attribute, value)
  if zen.objects[name] then
    zen.objects[name][attribute] = value
  else
    err("Object Doesn't Exist")
  end
end
zen.graphics.square = function(colour, x, y, width, height)
  term.setBackgroundColour(colour)
  for i = 1, height do
    term.setCursorPos(x, y)
    print(string.rep(" ", width))
    y = y + 1
  end
end
local draw = function()
  for 1k, 1v in pairs(zen.objects) do
    for 2k, 2v in pairs(zen.objects[1v]) do
	  if zen.objects[1v][image] then
	    if not zen.objects[1v][x] then
		  zen.objects[1v][x] = 1
	    end
	    if not zen.objects[1v][y] then
		  zen.objects[1v][y] = 1
	    end
	  end
    end
  end
  sleep(0.05)
end
local quit = function()
  local eDat = {os.pullEvent()}
  if eDat[1] == "key" then
    if eDat[2] == keys.q then
	  err("Exited by User")
    end
  end
end
local evt = { }
zen.run = function()
  local q = coroutine.create(quit)
  local d = coroutine.create(draw)
  while true do
    if coroutine.status(q) == "dead" then
	  q = coroutine.create(quit)
    end
    if coroutine.status(d) == "dead" then
	  d = coroutine.create(draw)
    end
    coroutine.resume(q, unpack(evt))
    coroutine.resume(d, unpack(evt))
    evt = {os.pullEvent()}
  end
end
zen.run() -- For Testing Only
Bomb Bloke #2
Posted 10 December 2014 - 11:20 AM
Variable names may not begin with a numeral.
cdel #3
Posted 10 December 2014 - 11:21 AM
Variable names may not begin with a numeral.

Cant believe I didn't catch onto that, thanks :)/>