Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...