Posted 05 January 2014 - 02:31 AM
Hey there,
I'm currently working on an OS for my Tekkit Classic server, which users can optionally install and make full use of server programs, like email, chats, and other programs for example for checking out the rules, if they have to.
I'm currently working on the OS selection screen, where users can select whether they want to boot up to CraftOS or BeastOS (I know, it sounds like I'm a kid if you judge by the name, but the server's called CreepyBeast Tekkit, and CreepyOS sounds even weirder.).
I'm trying to use the keys API, but for some reason, I always get: startup:63: attempt to call index ? (a nil value)
and then the program exits.
I'm guessing this is because CC 1.3 doesn't have the constants found in the keys API.
How can I work around this and still get the keys? I'm looking at the keyboard layout, found on the wiki, but I'd like to be sure before I just frustrate myself.
This is the code I'm using:
Thanks in advance for your help! :)/>
I'm currently working on an OS for my Tekkit Classic server, which users can optionally install and make full use of server programs, like email, chats, and other programs for example for checking out the rules, if they have to.
I'm currently working on the OS selection screen, where users can select whether they want to boot up to CraftOS or BeastOS (I know, it sounds like I'm a kid if you judge by the name, but the server's called CreepyBeast Tekkit, and CreepyOS sounds even weirder.).
I'm trying to use the keys API, but for some reason, I always get: startup:63: attempt to call index ? (a nil value)
and then the program exits.
I'm guessing this is because CC 1.3 doesn't have the constants found in the keys API.
How can I work around this and still get the keys? I'm looking at the keyboard layout, found on the wiki, but I'd like to be sure before I just frustrate myself.
This is the code I'm using:
-- BeastOS OS Selection
-- (c) Beatsleigher 2014
--[[ Disable Program Termination ]]--
os.pullEvent = os.pullEventRaw
--[[ Variables ]]--
local width, height = term.getSize()
local selectedIndex = 1
--[[ Handlers ]]--
local function BeastOS()
print("Please wait. Booting BeastOS.")
end
local function CraftOS()
end
--[[ Tables ]]--
osSelection = {
[1] = { text = "Boot BeastOS", handler = BeastOS },
[2] = { text = "Boot CraftOS", handler = CraftOS }
}
--[[ Print Methods ]]--
local function printCentre(_height, data)
xPos = width / 2 - string.len(data) / 2
term.setCursorPos(xPos, _height)
print(data)
term.setCursorPos(1, _height + 1)
end
local function printTopRight(data)
xPos = width - string.len(data)
term.setCursorPos(xPos, 1)
print(data)
term.setCursorPos(1, 2)
end
local function printHeader()
printCentre(1, "BEASTOS OS SELECTION MENU")
printTopRight("V1,0")
end
local function printMenu()
curCursorHeight = 3
for i = 1, #osSelection do
if osSelection[i] == osSelection[selectedIndex] then
printCentre(curCursorHeight, ">> "..osSelection[i].text.." <<")
curCursorHeight = curCursorHeight + 1
else
printCentre(curCursorHeight, osSelection[i].text)
curCursorHeight = curCursorHeight + 1
end
end
end
--[[ Other Handlers ]]--
local function onKeyPressed(key, menu)
if key == 28 then
onItemSelected(osSelection)
elseif key == 200 then
if selectedIndex > 1 then
selectedIndex = selectedIndex - 1
end
elseif key == 208 then
if selectedIndex < #osSelection then
selectedIndex = selectedIndex + 1
end
end
end
local function onItemSelected(menu)
menu[selectedIndex].handler()
end
--[[ Program Entry Point ]]--
term.clear()
printHeader()
printMenu()
event, key = os.pullEvent("key")
onKeyPressed(key, osSelection)
Thanks in advance for your help! :)/>
Edited on 05 January 2014 - 01:46 AM