(Sorry for the quality of my code i know its not pretty)
Spoiler
Thanks in advance
Posted 23 June 2013 - 02:25 PM
Posted 23 June 2013 - 02:46 PM
function test()
print("test")
end
test()
-- Doesnt work:
test()
function test()
print("test")
end
Posted 23 June 2013 - 03:00 PM
Posted 23 June 2013 - 04:17 PM
local function menu(startX,startY,bgcol,txtcol,markcol,options)
local currY = startY
local selected = 1
local function redraw()
term.setBackgroundColor(bgcol)
term.clear()
for i = 1, #options do
term.setCursorPos(startX, currY)
if i == selected then
term.setTextColor(markcol)
term.write("[")
term.setTextColor(txtcol)
term.write(options[i])
term.setTextColor(markcol)
term.write("]")
else
term.setTextColor(txtcol)
term.write(options[i])
end
end
end
while true do
local sEvent, sKey = os.pullEvent()
if sEvent == "key" then
if sKey == keys.up then
if selected == 1 then
selected = #options
else
selected = selected - 1
end
elseif sKey == keys.down then
if selected == #options then
selected = 1
else
selected = selected + 1
end
elseif sKey == keys.enter then
return options[selected]
end
redraw()
sleep(0)
end
end
--Creating a new menu
local spawnMenu = menu(5,5,colors.brown,colors.gray,colors.lime,{"Mob1","Mob2","Mob3"})
--Interacting with the output
if spawnMenu == "Mob1" then
--Do something
elseif spawnMenu == "Mob2" then
--Do something
elseif spawnMenu == "Mob3" then
--Do something
end
Posted 23 June 2013 - 04:38 PM
Freack100, on 23 June 2013 - 04:17 PM, said:
local function menu(startX,startY,bgcol,txtcol,markcol,options)
local currY = startY
local selected = 1
local function redraw()
term.setBackgroundColor(bgcol)
term.clear()
for i = 1, #options do
term.setCursorPos(startX, currY)
if i == selected then
term.setTextColor(markcol)
term.write("[")
term.setTextColor(txtcol)
term.write(options[i])
term.setTextColor(markcol)
term.write("]")
else
term.setTextColor(txtcol)
term.write(options[i])
end
end
end
while true do
local sEvent, sKey = os.pullEvent()
if sEvent == "key" then
if sKey == keys.up then
if selected == 1 then
selected = #options
else
selected = selected - 1
end
elseif sKey == keys.down then
if selected == #options then
selected = 1
else
selected = selected + 1
end
elseif sKey == keys.enter then
return options[selected]
end
redraw()
sleep(0)
end
end
--Creating a new menu
local spawnMenu = menu(5,5,colors.brown,colors.gray,colors.lime,{"Mob1","Mob2","Mob3"})
--Interacting with the output
if spawnMenu == "Mob1" then
--Do something
elseif spawnMenu == "Mob2" then
--Do something
elseif spawnMenu == "Mob3" then
--Do something
end
0 members, 1 guests, 0 anonymous users