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

[SOLVED][LUA] Arrowkey control

Started by Engineer, 28 January 2013 - 01:27 AM
Engineer #1
Posted 28 January 2013 - 02:27 AM
Hello,

this is my attempt on a sort of little GUI or UI or I dont know how its called. This is going to be in my latest program (see signature) and I am a loss what to do now.

This was my attempt:


print("Select functionality with arrowkeys, enter to continue.\n")
while true do
print(" [ Bone Meal ]   Natural grow ")
local p1 = os.pullEvent("key")
if p1 == 205 then
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,2)
print("   Bone Meal   [ Natural Grow ]")
local param1 = os.pullEvent("key")
if param1 == 203 then
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,2)
print(" [ Bone Meal ]   Natural grow ")
elseif param1 == 28 then
break
end
elseif p1 == 28 then
meal = meal + 1
break
end
end
I prefer pastebin: http://pastebin.com/XSvaZgHv

Thanks for the help

Hope you guys can help me out :)/>
ikke009 #2
Posted 28 January 2013 - 03:49 AM
try this

print("Select functionality with arrowkeys, enter to continue.\n")
select = nil
  term.setCursorPos(1,2)
  write(" Bone Meal Natural Grow")
while true do
  local ev, p1 = os.pullEvent("key")
  if p1 == 205 then
	term.setCursorPos(1,2)
	term.clearLine()
	write("   Bone Meal   [ Natural Grow ]")
	select = 2
  elseif p1 == 203 then
	term.setCursorPos(1,2)
	term.clearLine()
	print(" [ Bone Meal ]   Natural grow ")
	select = 1
  elseif p1 == 28 then
	break
  end
  if select == 1 then
	meal = meal + 1
  end
end

Next time make clear what the problem is, i now assumed it simply didnt work
Engineer #3
Posted 28 January 2013 - 08:17 AM
try this

print("Select functionality with arrowkeys, enter to continue.\n")
select = nil
  term.setCursorPos(1,2)
  write(" Bone Meal Natural Grow")
while true do
  local ev, p1 = os.pullEvent("key")
  if p1 == 205 then
	term.setCursorPos(1,2)
	term.clearLine()
	write("   Bone Meal   [ Natural Grow ]")
	select = 2
  elseif p1 == 203 then
	term.setCursorPos(1,2)
	term.clearLine()
	print(" [ Bone Meal ]   Natural grow ")
	select = 1
  elseif p1 == 28 then
	break
  end
  if select == 1 then
	meal = meal + 1
  end
end

Next time make clear what the problem is, i now assumed it simply didnt work

Thank you so much! It worked for me :)/> It is highly appreciated :D/>
ikke009 #4
Posted 28 January 2013 - 08:58 AM
any time mate