So I'm would like to have a selection thing like the one that the worm program has! Before I have used local bla = read() and then had a number to select but I want to get a little bit more advance! Is there a way to make something like this that dont take up tons of place with code? I have seen some examples but that havn't really worked...
Tnx!
//Elis
3
7 replies to this topic
#1
Posted 02 February 2013 - 05:38 AM
#2
Posted 02 February 2013 - 06:28 AM
take a look at my menu functions in my sig. you would want the basic menu example, no scrolling or anything
#3
Posted 02 February 2013 - 07:05 AM
Well, it's basically a while true do with an os.pullEvent() (waiting for the key event) until enter is pressed.
Something like this? If you need me to explain anything, ask away />/>
Something like this? If you need me to explain anything, ask away />/>
screenX, screenY = term.getSize() t = { colSel = colours.yellow, colNotSel = colours.lime, difficulties = { { text = "Easy", diffLevel = 1, diffSpeed = 1 }, { text = "Medium", diffLevel = 2, diffSpeed = 0.5 }, { text = "Hard", diffLevel = 3, diffSpeed = 0.1 } } } function getDifficulty() local sel = 1 -- define which option is selected by default while true do for i = 1, #t.difficulties do term.setCursorPos(math.floor((screenX-#t.difficulties[i].text)/2), math.floor(screenY/2) - 1 + i) term.setTextColour(i == sel and t.colSel or t.colNotSel) write(t.difficulties[i].text) end _, key = os.pullEvent("key") if key == keys.down and sel < #t.difficulties then sel = sel + 1 elseif key == keys.up and sel > 1 then sel = sel - 1 elseif key == keys.enter then return t.difficulties[sel].text, t.difficulties[sel].diffLevel, t.difficulties[sel].diffSpeed end end end term.clear() difficulty, level, speed = getDifficulty() term.clear() term.setCursorPos(1, 1) term.setTextColour(colours.yellow) print( "You chose the difficulty '" .. difficulty .. "' which has the difficulty level of " .. level .. " and speed of " .. speed .. ".\n\nGoodluck!\n" ) term.setTextColour(colours.white)
#4
Posted 02 February 2013 - 10:17 AM
remiX, on 02 February 2013 - 07:05 AM, said:
Well, it's basically a while true do with an os.pullEvent() (waiting for the key event) until enter is pressed.
Something like this? If you need me to explain anything, ask away />/>
Something like this? If you need me to explain anything, ask away />/>
screenX, screenY = term.getSize() t = { colSel = colours.yellow, colNotSel = colours.lime, difficulties = { { text = "Easy", diffLevel = 1, diffSpeed = 1 }, { text = "Medium", diffLevel = 2, diffSpeed = 0.5 }, { text = "Hard", diffLevel = 3, diffSpeed = 0.1 } } } function getDifficulty() local sel = 1 -- define which option is selected by default while true do for i = 1, #t.difficulties do term.setCursorPos(math.floor((screenX-#t.difficulties[i].text)/2), math.floor(screenY/2) - 1 + i) term.setTextColour(i == sel and t.colSel or t.colNotSel) write(t.difficulties[i].text) end _, key = os.pullEvent("key") if key == keys.down and sel < #t.difficulties then sel = sel + 1 elseif key == keys.up and sel > 1 then sel = sel - 1 elseif key == keys.enter then return t.difficulties[sel].text, t.difficulties[sel].diffLevel, t.difficulties[sel].diffSpeed end end end term.clear() difficulty, level, speed = getDifficulty() term.clear() term.setCursorPos(1, 1) term.setTextColour(colours.yellow) print( "You chose the difficulty '" .. difficulty .. "' which has the difficulty level of " .. level .. " and speed of " .. speed .. ".\n\nGoodluck!\n" ) term.setTextColour(colours.white)
I havn't looked much into the code yet but I will soon, just thought I could ask now to maybe save some time
#5
Posted 02 February 2013 - 11:18 AM
Hmm, how do you mean? So it brings up the list of certain programs and clicking enter will run them?
Well, using fs.list("/") will give you a table with all programs and directories of the computer (excluding rom) in which you can print that list and then clicking enter will run it using shell.run("program")
Well, using fs.list("/") will give you a table with all programs and directories of the computer (excluding rom) in which you can print that list and then clicking enter will run it using shell.run("program")
#6
Posted 02 February 2013 - 11:19 AM
It is my personal opinion that one should not be dabbling in code that they do not wish to learn for themselves in order to reap the benefits of gratification.
EDIT:
By this I mean that if you aren't taking the time to understand what you're working with, you shouldn't be working with it.
EDIT:
By this I mean that if you aren't taking the time to understand what you're working with, you shouldn't be working with it.
#7
Posted 03 February 2013 - 01:34 AM
KingMachine, on 02 February 2013 - 11:19 AM, said:
It is my personal opinion that one should not be dabbling in code that they do not wish to learn for themselves in order to reap the benefits of gratification.
EDIT:
By this I mean that if you aren't taking the time to understand what you're working with, you shouldn't be working with it.
EDIT:
By this I mean that if you aren't taking the time to understand what you're working with, you shouldn't be working with it.
A very true statement... some people seek gratification though and I suppose if that is what they want I wouldn't stop them
#8
Posted 04 February 2013 - 12:28 AM
KingMachine, on 02 February 2013 - 11:19 AM, said:
It is my personal opinion that one should not be dabbling in code that they do not wish to learn for themselves in order to reap the benefits of gratification.
EDIT:
By this I mean that if you aren't taking the time to understand what you're working with, you shouldn't be working with it.
EDIT:
By this I mean that if you aren't taking the time to understand what you're working with, you shouldn't be working with it.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users