And thanks for checking this out!
Ok, ok… I'll cut the crap, dive straight into it! :D/>/>
So there is this larger project I've been working on, but I cannot seem to get it working!
Now I've used computercraft for a very long time, and I once wrote an UI with build in APIs and alot of handy utilities on a server.
But that server shut down, I don't know what the owner was thinking.
So I lost ~2000 lines of almost releasable code! (Well at least for the first version :P/>/> )
Now I've decided to rewrite the whole thing, but I wanted to change the layout for the choosing of options in menus.
I decided to do this kind of thingy that you can scroll with the arrow keys, up and down, and in bigger menus, to the sides.
But I got stuck very early when facing a problem in my loop. Here is the code, I'll explain the problem!
Spoiler
--
-- Part of a project, made by Cedric.
--
--
-- In Minecraft, using computercraft.
--
--
os.loadAPI("/ui/uiBase") -- Loads an api I made for frames for the menus and such
local choice = 1 -- what choice you made in the menu
function menu() -- a function drawing the menu
uiBase.frame() -- a function from uiBase
term.setCursorPos(20, 7) -- !
write "Login" --Just
term.setCursorPos(20, 8) --Some
write "Register" --Options
term.setCursorPos(20, 9) --Over
write "About" --Here
term.setCursorPos(20, 10) -- !
write "Shutdown"
return
end
while true do -- A loop for updating the screen and for inputting new inputs
shell.run("clear") -- clears the screen
menu() -- my function
if choice == 1 then -- draws a pointer for the selected choice
term.setCursorPos(19, 7) --
write ">" -- same here
elseif choice == 2 then
term.setCursorPos(19, 8)
write ">" -- I think you get my point here
elseif choice == 3 then
term.setCursorPos(19, 9)
write ">"
elseif choice == 4 then
term.setCursorPos(19, 10)
write ">"
end
event, param1 = os.pullEvent("key") -- Waiting for a key to be pressed
if event == "key" and param1 == "200" then -- If the key pressed was "up"
choice = choice - 1 -- Scrolls up the list
elseif event == "key" and param1 == "208" then --If the key pressed was "down"
choice = choice + 1 -- scrolls down the list
elseif event == "key" and param1 == "28" then -- if the key pressed was "ENTER"
if choice == 1 then -- Going into the...
shell.run("loginMenu") -- login menu
elseif choice == 2 then
shell.run("registerMenu") --registering menu
elseif choice == 3 then
shell.run("aboutText") --"about" screen
elseif choice == 4 then
shell.run("shutdownCustom") -- shuts down the computer
end
if choice == 5 then -- you cant go outside the menu
choice = 4
elseif choice == 0 then
choice = 1
end
end
end -- It just wanted that. wth?
Now the problem is that when the menu pops up, the selection marker shows up, but I can't get it to react! So the os.pullEvent() most have frozen there somehow, nothing reacts, you have to terminate the program to get out. I've scratched my head for a time now, but then I found this forum!
Help me ComputerCraft forum, you're my only hope… *Star wars reference*