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

Menu to run functions trouble.

Started by Reganom, 19 May 2013 - 02:02 PM
Reganom #1
Posted 19 May 2013 - 04:02 PM
I'm trying to create an xp turtle program that allows the user to run certain functions, mainly: Just collecting levels, enchanting one item, auto enchanting items.

I'm stuck at to how to best accomplish that. My current idea is to have 4 seperate programs with shell.run to swap to the correct program.

The main problem is it's not responding the way i'd expect. Nothing is shown untill i enter a keypress then it seems to start up. I'm also worried I'm over thinking the entire thing and that I can do it all in one program. Any advice would be great. Thanks

Spoiler

--enchanting menu

local level=read()

function clearScreen()
	term.clear()
	term.setCursorPos(1,1)
end

function menu ()
	clearScreen()
	print("Reganom's Enchanting")
	print("1:Enchant items")
	print("2:Auto Enchanter")
	print("3:Auto Collecter")
	print("Select an option:", read())
end

function levelSelect()
	clearScreen()
	print("What level would you like to enchant at?"
	print("Level:", read())
	end
end

while true do
	menu()	
local e, key = os.pullEvent('key')
	if e == 1 then
		levelSelect() -- should run levelSelect() which is then used in the shell.run as for the next program
		shell.run("one", level)
	elseif e == 2 then
		levelSelect()
		shell.run("two", level)
	elseif e == 3 then
		shell.run("three")
	else
	end
end
Lyqyd #2
Posted 20 May 2013 - 12:36 AM
Split into new topic.
LBPHacker #3
Posted 20 May 2013 - 04:33 AM
local e, key = os.pullEvent('key')
You have to chech key instead of e, because e is "key" anyways (thanks to .pullEvent). key contains a keycode you can check, but I think you should use the char event though:
while true do
    menu()  
    local event, char = os.pullEvent("char")
    if char == "1" then
        levelSelect() -- should run levelSelect() which is then used in the shell.run as for the next program
        shell.run("one", level)
    elseif char == "2" then
        levelSelect()
        shell.run("two", level)
    elseif char == "3" then
        shell.run("three")
    else
    end
end