Jump to content




[SOLVED][LUA] Arrowkey control


  • You cannot reply to this topic
3 replies to this topic

#1 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

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 :)

#2 ikke009

  • Members
  • 224 posts
  • LocationSliding between sunbeams

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

#3 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 28 January 2013 - 08:17 AM

View Postikke009, on 28 January 2013 - 03:49 AM, said:

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

#4 ikke009

  • Members
  • 224 posts
  • LocationSliding between sunbeams

Posted 28 January 2013 - 08:58 AM

any time mate





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users