Jump to content




GUI Help


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

#1 koslas

  • Members
  • 62 posts
  • LocationChristchurch, New Zealand

Posted 06 August 2012 - 05:54 AM

I am currently trying to make a OS with a GUI, but when I try and launch the program it doesn't seem to let the arrows work (Left and Right arrows). I have made sure I had the arrows configured. Another error I noticed is a bug where when I launch the program It doesn't work until I press a key.
I have not added the functions for the options yet.

Here is the code:

--No Terminate

os.pullEvent = os.pullEventRaw

--Rednet

rednet.open("top")
rednet.open("bottom")
rednet.open("left")
rednet.open("right")
rednet.open("front")
rednet.open("back")

--

--GUI

local option = {}
option[1] = "[Login] Register  Exit"
option[2] = " Login [Register] Exit"
option[3] = " Login  Register [Exit]"

--Login Function

function login()
end

--Register Function

function register()
end

--Exit Function

function exit()
end

--Goto Function

function gotoMenu(i)
	if i == 1 then
		login()
	elseif i == 2 then
		register()
	elseif i == 3 then
		exit()
	end
end

--Option Function

function options(i)
	if not i then
		i = 1
	end
	term.clear()
	term.setCursorPos(1,1)
	print(option[i])
		event, key = os.pullEvent("key")
while true do
		if key == 203 and not i == 1 then
			return options(i - 1)
		elseif key == 205 and not i == 3 then
			return options(i + 1)
		elseif key == 28 then
			return gotoMenu(i)
		end
	end
end

options()


#2 brett122798

  • Members
  • 300 posts
  • LocationIn the TARDIS at an unknown place in time.

Posted 06 August 2012 - 05:57 AM

I'm still reviewing your arrow key thing, but I noticed a problem with your gotoMenu function. int cannot be used as an argument, so replace it with anything else. Ex: number

EDIT: Okay, I don't know if it'll make a difference, but in my code, the key thing looks like this:

local e,key = os.pullEvent("key")

Instead of your this:

event, key = os.pullEvent("key")


#3 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 06 August 2012 - 05:58 AM

Well, you're telling it to print after it receives a key event. You should probably have the clear screen and the print before the event pull.

#4 koslas

  • Members
  • 62 posts
  • LocationChristchurch, New Zealand

Posted 06 August 2012 - 07:11 AM

Problem Fixed

#5 Noodle

  • Members
  • 989 posts
  • LocationSometime.

Posted 06 August 2012 - 09:26 AM

View Postbrett122798, on 06 August 2012 - 05:57 AM, said:

I'm still reviewing your arrow key thing, but I noticed a problem with your gotoMenu function. int cannot be used as an argument, so replace it with anything else. Ex: number

EDIT: Okay, I don't know if it'll make a difference, but in my code, the key thing looks like this:

local e,key = os.pullEvent("key")

Instead of your this:

event, key = os.pullEvent("key")
It works both ways..

#6 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 06 August 2012 - 02:02 PM

try this out

ops={"login", "register", "exit"}
rps={login, register, exit}
function menu(options,responses,initialselect)
local selected=initialselect or 1
while true do
term.clear()
term.setCursorPos(1,1)
local numberofoptions=0
for delim,opt in pairs(options) do
if delim==selected then
  write("[")
end
write(opt)
if delim==selected then
  write("]")
end
numberofoptions=numberofoptions+1
end
local event,param1=os.pullEvent("key")
if param1==203 and selected~=1 then
selected=selected-1
elseif param1==205 and selected~=numberofoptions then
selected=selected+1
elseif param1==28 then
return responses[selected]()
end
end
end


menu(ops,rps,2)

then rename the 3 things in rps to your three functions you want to call when you select something





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users