Posted 30 September 2012 - 02:38 AM
Hello everyone, and thanks for any help you can provide.
I want to start off by saying that I am using ComputerCraft 1.4.2 for Minecraft 1.3.2. Not sure if it makes any difference but I try to be thorough.
I am attempting to create a menu system to control my inventory/crafting system, reactors, and turtles in my upcoming 1.3.2 world. I am using the system shown here http://pastebin.com/wVkzaqF7 by Grim Reaper, to identify which option I am selecting. This system surrounds the selected option name with brackets and uses os.pullEvent("key") to change the selection with the up and down arrow keys.
My problem is only visual. While the code does work and changes the selection, thereby allowing me to move through menus and selections within them; it does not show this. When I test by printing only a single menu ie: boot menu drawBoot() it works, showing me moving through the selections, but when I use tMenus[menustate].draw() so that I can select other menus to display it displays the new menus when I select them (enter key) but it does not show the changing of selections within a menu.
Sorry if this isn't entirely clear but it's easier if you just try it yourself. You can see the problem by changing between drawBoot() and tMenus[menustate].draw()
Here's the pastebin to try my code yourself: http://pastebin.com/j85k7eQN
Code:
I want to start off by saying that I am using ComputerCraft 1.4.2 for Minecraft 1.3.2. Not sure if it makes any difference but I try to be thorough.
I am attempting to create a menu system to control my inventory/crafting system, reactors, and turtles in my upcoming 1.3.2 world. I am using the system shown here http://pastebin.com/wVkzaqF7 by Grim Reaper, to identify which option I am selecting. This system surrounds the selected option name with brackets and uses os.pullEvent("key") to change the selection with the up and down arrow keys.
My problem is only visual. While the code does work and changes the selection, thereby allowing me to move through menus and selections within them; it does not show this. When I test by printing only a single menu ie: boot menu drawBoot() it works, showing me moving through the selections, but when I use tMenus[menustate].draw() so that I can select other menus to display it displays the new menus when I select them (enter key) but it does not show the changing of selections within a menu.
Sorry if this isn't entirely clear but it's easier if you just try it yourself. You can see the problem by changing between drawBoot() and tMenus[menustate].draw()
Here's the pastebin to try my code yourself: http://pastebin.com/j85k7eQN
Code:
Spoiler
-- -- TechOS -- --
-- Local Variables --
local nScreenWidth, nScreenHeight = term.getSize()
local nSelection = 1
local menustate = "Boot"
-- End Local Variables --
-- Local Tables --
local tMenus = {
[ "Boot" ] = {
options = { "Inventory", "Turtles", "Reactor" },
draw = drawBoot
},
[ "Inventory" ] = {
options = { "Raw Materials", "Refined Materials" },
draw = drawInventory
},
[ "Turtles" ] = {
options = { "Mining" },
draw = drawTurtles },
[ "Reactor" ] = {
options = { "Control" },
draw = drawReactor
}
}
-- End Local Tables --
-- -- Draw Functions -- --
-- Base Draw Functios --
function ClearScreen()
term.clear()
term.setCursorPos( 1, 1 )
end
function PrintCentered( nHeight, sString )
term.setCursorPos( nScreenWidth/2 - #sString/2, nHeight )
term.write( sString )
end
function PrintLeft( nHeight, sString )
term.setCursorPos( 1, nHeight )
term.write( sString )
end
function PrintRight( nHeight, sString )
term.setCursorPos( ( nScreenWidth + 1 ) - #sString, nHeight )
term.write( sString )
end
function PrintTitle( sName )
PrintCentered( 1, string.rep( "-", ( nScreenWidth + 1 ) ) )
PrintCentered( 2, string.rep( "-", ( nScreenWidth + 1 ) ) )
PrintLeft( 3, "-" )
PrintCentered( 3, sName )
PrintRight( 3, "-" )
PrintCentered( 4, string.rep( "-", ( nScreenWidth + 1 ) ) )
PrintCentered( 5, string.rep( "-", ( nScreenWidth + 1 ) ) )
for i = 6, ( nScreenHeight - 1 ) do
PrintLeft( i, "-" )
PrintRight( i, "-" )
PrintCentered( nScreenHeight, string.rep( "--", ( nScreenWidth + 1 ) ) )
end
end
-- End Base Draw Functions
-- Menu Draw Functions --
function drawBoot()
PrintTitle( "Boot Menu" )
for j = 1, 3 do
if j == nSelection then
PrintCentered( 11 + ( j - 1 ), "[" .. tMenus["Boot"].options[j] .. "]" )
else
PrintCentered( 11 + ( j - 1 ), " " .. tMenus["Boot"].options[j] .. " " )
end
end
end
function drawInventory()
PrintTitle( "Inventory Menu" )
for k = 1, 2 do
if k == nSelection then
PrintCentered( 11 + ( k - 1 ), "[" .. tMenus["Inventory"].options[k] .. "]" )
else
PrintCentered( 11 + ( k - 1 ), " " .. tMenus["Inventory"].options[k] .. " " )
end
end
end
-- End Menu Draw Functions --
-- -- End Draw Functions -- --
while true do
ClearScreen()
-- -- Problem lies here -- --
-- drawBoot() -- shows changing of selections
tMenus[menustate].draw() -- doesn't show changing of selections
local id, nKey = os.pullEvent("key")
if nKey == 200 and nSelection > 1 then
nSelection = nSelection - 1
elseif nKey == 208 and nSelection < #tMenus[menustate].options then
nSelection = nSelection + 1
elseif nKey == 28 then
menustate = tMenus[menustate].options[nSelection]
end
end