Lua with Gui
Problem:
I am trying to make a Gui that has info on items. Right now I can use it but after 2 buttons are selected it stops working well. The word stone just keeps poping up if you click enter or try to scroll.
Possible upgrades:
I want to be able to also scroll up because there is to much text. Half of what I have is hidden. Maybe make "bottons" that don't work but are placed beside everyline so they can scroll up the bottons to see the rest of the text. And at the bottom (it is already there) the options for other pages and the exit button. Thanks.
Pastebin version of script:
http://pastebin.com/TieR2P5r
Lua script (What I got so far):
local function menu(...)
local sel = 1
local list = {...}
local offX,offY = term.getCursorPos()
local curX,curY = term.getCursorPos()
while true do
if sel > #list then sel = 1 end
if sel < 1 then sel = #list end
for i = 1,#list do
term.setCursorPos(offX,offY+i-1)
if sel == i then
print("["..list[i].."]") -- very customisible example print(">"..list[i])
else
print(" "..list[i].." ") -- very customisible
end
end
while true do
local e,e1,e2,e3,e4,e5 = os.pullEvent()
if e == "key" then
if e1 == 200 then -- up key
sel = sel-1
break
end
if e1 == 208 then -- down key
sel = sel+1
break
end
if e1 == 28 then
term.setCursorPos(curX,curY)
return list[sel],sel
end
end
end
end
end
function Option1()
shell.run("clear")
print"(Stone, also known as Smooth Stone, is a block found in")
print("abundance in the Overworld. It uses the same texture on all")
print("six sides of the block. When mined, stone produces cobblestone.")
print("")
print("Stone is an often-used building material in the construction")
print("of buildings, paths and many other things.")
print("")
print("After air, stone is the second most common block found in a")
print("normal map.")
print("")
print("EMC: 1")
print("Blast Resistance: 30")
print("ID: 1")
end
function Option2()
shell.run("clear")
print("A Grass Block is a block that was introduced very early in the")
print("game. It uses 4 textures: a gray one for the top which is then")
print("tinted to the correct color according to what biome the block is")
print("in, one borrowed from the dirt block for the bottom, an edited")
print("dirt texture with grass on the top edge on all of the sides, and")
print("a gray texture matching the shape of the grass on the side of")
print("the block, which is tinted to the correct biome color. When")
print("covered by snow the side texture is white. On natural maps,")
print("grass appears on topmost blocks of dirt with no fluids or opaque")
print("solid blocks above them.")
print("")
print("In mining, grass blocks behave just like dirt - they drop dirt")
print("resources and are best dug with a shovel; however, they make a")
print("different sound when harvested and take slightly longer to dig up.")
print("This can be used to tell when the player is about to break the")
print("surface when tunneling upwards.")
print("")
print("EMC: 1")
print("Blast Resistance: 3")
print("ID: 2")
end
function Option3()
shell.run("clear")
print("Dirt is a block found abundantly in the Overworld. It uses the same")
print("texture on all six sides of the block. This is a block often used")
print("when making a temporary shelter quickly since it is commonly found.")
print("Dirt makes up the majority of the top layers of blocks, between grass,")
print("snow and stone. It is also found underground in clumps in all")
print("altitudes and in the bottom of lakes and oceans. It is a very weak")
print("block and is easily destroyed in explosions from TNT or Creepers,")
print("making dirt shelters a fallback option at best.")
print("")
print("When a dirt block is adjacent to a grass block and is exposed to a")
print("light level of at least 4 (e.g. from torches or sunlight), it will")
print("eventually be converted into a grass block; when this happens is")
print("random and unpredictable (see grass for growth details). Dirt can also")
print("have mycelium spread on to the block in much the same way, but")
print("requiring a light level of at least 9.")
print("")
print("Dirt will always drop a resource block, regardless of how it was mined.")
print("It may be mined by hand fairly quickly, but using a shovel will")
print("significantly speed up the process.")
print("")
print("Using a hoe on a placed block of dirt will turn it into a farmland block,")
print("enabling seeds to be planted on it. Farmland will revert to dirt unless")
print("something is planted on it or it is irrigated by nearby water.")
print("")
print("EMC: 1")
print("Blast Resistance: 2.5")
print("ID: 3")
end
function Option4()
shell.run("clear")
print("Cobblestone is a common block used for creating various items, that")
print("resembles an uneven, roughly paved surface. Cobblestone only occurs")
print("naturally in dungeons, NPC Villages, strongholds, or when water and")
print("flowing lava come into contact. It is commonly used to create walls for")
print("constructions with a medieval appearance such as castles, towers and roads.")
print("Cobblestone is obtained by mining stone. Cobblestone is slightly harder to")
print("mine than normal stone, and there is an alternative version of the block")
print("known as Moss Stone. Silverfish have the ability to enter and hide in")
print("cobblestone.")
print("EMC: 1")
print("Blast Resistance: 30")
print("ID: 4")
end
function Option5()
shell.run("clear")
error()
end
while true do
local selection = menu(
"Stone 1",
"GrassBlock 2",
"Dirt 3",
"Cobblestone 4",
"Exit")
if selection == "Stone 1" then
Option1()
elseif selection == "GrassBlock 2" then
Option2()
elseif selection == "Dirt 3" then
Option3()
elseif selection == "Cobblestone 4" then
Option4()
elseif selection == "Exit" then
Option5()
end
end
If you can help me I would very much thank you for it!