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

[help] key input error [ithink]

Started by LuaEclipser, 19 March 2013 - 09:47 AM
LuaEclipser #1
Posted 19 March 2013 - 10:47 AM
here is my program - http://pastebin.com/QKiggtga

i want it to just print a "-" (its a "test" arrow)

why wont it work?

thanjk you!
TheOddByte #2
Posted 19 March 2013 - 11:11 AM
Well you havent declared weapon as bow yet I think..
And you would have it paus for like a second to see it,,
And it isn't good to have the function called weapon as the string since you could get this error

attempt to call string
And you won't get it the first time you do it
but the second time..


Here's the code if you just want to test and see it..
Spoiler


--SECTION 1, VARIABLES
local posX, posY = 5, 5
local w,h = term.getSize()
weapon = "bow"
local char = {
" ",
"@",
" ",
}
local arrow = {
"-"
}

--ART FUNCTIONS

function printCenter(str, nolp)
  term.setCursorPos(w/2 - #str/2, nolp)
  term.write(str)
end

function printRight(str, nolpW)
  term.setCursorPos(w - #str, nolpW)
  term.write(str)
end

function drawHeader()
  printCenter("Game!", 1)
  printCenter(string.rep("#", w), 2)
end

local function picture(image,positionX,positionY)
		for y = 1,#image do
				term.setCursorPos(positionX,positionY + y - 1)
				term.write(image[y])
		end
end


--weapon functions

function hWeapon()
weapon = "bow"
  if weapon == "bow" then
	print("_")
sleep(0.5)
  end  
end


--MOVMENT


while true do

		term.clear()
		drawHeader()
		picture(char,posX,posY)

		local event = {os.pullEvent()}

		  --Movement

		  if event[1] == "key" then
			if event[2] == 200 then --up
			  posY = posY - 1
			elseif event[2] == 208 then --down
			  posY = posY + 1
			elseif event[2] == 205 then --left
			  posX = posX + 1
			elseif event[2] == 203 then --right
			  posX = posX - 1
			elseif event[2] == 57 then
			  hWeapon()
			end
		 end

end

--Weapons
weapon = "bow"
arrow = {
"-"
}
--bow

while true do
  if weapon == "bow" then

  local event = {os.pullEvent()}

	if event[1] == "key" then
	  if event[2] == 57 then
		Xpos = Xpos - 1
	  end
	end
  end
end

Edit: Saw that the only error was that you did'nt paus anything so you could actually see it