Stevolution Posted September 8, 2012 Posted September 8, 2012 Still playing around with this Computercraft stuff. Slowly getting my head around it. Is there a way of setting a line or block name. And can you then setup a got style statement to it? The reason is, I have a program that has 5 options at the beginning. Depending on the input, I need to go to a certain part of the program. Then once completed, return back to the beginning of the program (but not restart it). Ideally, I need to name these 5 tasks and either gosub or goto them from the input loop. (oh - and how much programming can this little computer take?) edit: This doesn't seem to work: http://lua-users.org/wiki/GotoStatement Quote
gavjenks Posted September 8, 2012 Posted September 8, 2012 Goto statements are pure evil, and are not available in lua (or java), as far as I know. Nor should you seek them out, as they are never necessary and they make code vastly more difficult to understand (by somebody else or by yourself revisiting it later). In your case, it sounds like a very simple IF statement would be just fine. myVariable = (some input, 1-5) if myVariable == 1 do [blah] else if myVariable == 2 do [blah] ... etc. As for how much programming... If I recall, lua is not compatible with any sort of RAM cap. I think you can theoretically store as much disk space data as the host server running tekkit has available, and you can use as much RAM as the host server is allocating to tekkit, from any CC device. Quote
Watchful11 Posted September 8, 2012 Posted September 8, 2012 Goto statements are pure evil, and are not available in lua (or java), as far as I know. Nor should you seek them out, as they are never necessary and they make code vastly more difficult to understand (by somebody else or by yourself revisiting it later). Second this. Avoid goto's at all costs. Quote
warpspeed10 Posted September 8, 2012 Posted September 8, 2012 Try to avoid using goto statements no mater what language you program in. There is almost always another way to perform the same operation without a goto, and the use of them is generally considered bad technique. Quote
Stevolution Posted September 8, 2012 Author Posted September 8, 2012 Yes... I know.... goto's are the devils arse in the world of programming. However, I seems to be getting into a right old mess here. I have a routine that sets up the screen and a few other items. Then it waits for any change in redstone activity (the only way I seem to be able to stop it hogging computer resources). Once it detects a redstone change of any sort (standing on a pad), it then checks that input to make sure it was actually the pad and not something else that activated it. Then... its a password loop Then.... its enter a selection from a menu Then... do one of 5 things. So basically... loops within loops. But in such a small poxy programming window, its really hard to write anything of any size. Especially as you can only move with the arrow keys. I didn't care what it looked like. No-one else will ever see the coding. Quote
warpspeed10 Posted September 8, 2012 Posted September 8, 2012 Why use goto, when you can make the menu call different functions? Quote
disconsented Posted September 8, 2012 Posted September 8, 2012 To expand on GOTO's. Learn to use and love functions for any code that is used more than once. Quote
Stevolution Posted September 8, 2012 Author Posted September 8, 2012 Can anyone see where I am missing and 'end' statement. Its at the bottom somewhere. I am getting EOF in line 83 but I can't seem to get rid of it. pad = rs.testBundledInput ("back", 8192) extbut = rs.testBundledInput ("back", 64) while true do term.clear() term.setCursorPos(1,1) print " Nuclear Reactor Access Control" print " " redstone.setBundledOutput("back", 0) local mon = peripheral.wrap("right") mon.clear() mon.setTextScale(1) mon.setCursorPos(2,1) mon.write " Access System" mon.setCursorPos(2,3) mon.write " Terminal Clear " sleep(1) while true do local event = os.pullEvent() if event == "redstone" then break end end if pad == true then break else end sleep(1) rs.setBundledOutput("back" ,2048) sleep(7) rs.setBundledOutput("back" ,0) mon.setCursorPos(2,3) mon.write"Terminal Active" print"Please Enter Your Security Code" code = read("*") if code == "Tekkit" then break else rs.setBundledOutput("back", 1024) sleep(6.7) rs.setBundledOutput("back", 0) end end rs.setBundledOutput("back", 512) sleep(6.7) rs.setBundledOutput("back", 0) print"" print "(1) Access to Reactor Stage 1" sleep(.3) print "(2) Access to Control Room 1" sleep(.3) print "(3) Access to Control Room 2" sleep(.3) print "(4) Over-ride Reactor Lighting" sleep(.3) print "(5) Test Voice Audio Systems" sleep(1) print"" print"Select Required Function" nrdoor = "1" comd1 = "2" comd2 = "3" ligh = "4" aud = "5" input = read() if input == nrdoor then print"one" sleep(3) end elseif input == comd1 then print"two" sleep(3) end end There are some untidy bits I know.... still learning here. Last commands (print"two" etc) are just for testing. Quote
disconsented Posted September 8, 2012 Posted September 8, 2012 Before even reading this I have noticed two major flaws. No Indenting No Comments If you want anyone to understand your code you are going to have to get used to indenting and commenting. Quote
Stevolution Posted September 8, 2012 Author Posted September 8, 2012 wow thanks.. I only started last night. I will print it off and draw out the loops Quote
disconsented Posted September 8, 2012 Posted September 8, 2012 That will achieve nothing. Just learn to indent and comment, you will thank yourself if you ever need to revise your code and it is also just good practice. Quote
Stevolution Posted September 8, 2012 Author Posted September 8, 2012 Well I must be missing an end statement somewhere. So printing it off is easier to see all the code than the tiny little monitor on the computer. No worries. I will suss it out Quote
warpspeed10 Posted September 8, 2012 Posted September 8, 2012 Not missing an end, you have one too many. input = read() if input == nrdoor then print"one" sleep(3) end --Get rid of this end. elseif input == comd1 then print"two" sleep(3) end end Quote
Stevolution Posted September 8, 2012 Author Posted September 8, 2012 Thanks Warp. I noticed that when I printed it off. However it actually seems to make no difference. I added another while statement at the top, and that cured the EOF issue. Now, when its run through... I get a call to nil error instead. Quote
Stevolution Posted September 8, 2012 Author Posted September 8, 2012 Found it... capital 'S' on the sleep command. Its too late for programming. Thanks all Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.