Computercraft code/error help

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here

Feed the beast 122

New Member
Jul 29, 2019
101
0
0
Hey I'm kinda new to computer craft and am trying to get a test program to run correctly and when I do it I get this:

BIOS:339 [string "test"]:5: '<eof>' expected

The code is
If rs.getInput("left")
Then
OS.run("program name") (didn't want to put the actual program name here on the fourms but it is in the code)
End
Else
Print("flip the lever")

Need some serious help with this.
 

Arkandos

New Member
Jul 29, 2019
349
0
0
Firstly: Use the forums inbuilt code-function. Makes everything much easier to view.
Secondly: Use the actual file if you want help with anything CC-related. If you just type it here like you did, nobody knows what the real program does/ where the problem lies.

Change your code to
Code:
if rs.getInput("left") then
  shell.run("program name")
else
  print("Flip the lever")
end

Be aware that this code will only run once. And if you want to to continuosly check, you'll need some kind of loop
 

casilleroatr

New Member
Jul 29, 2019
1,360
0
0
The error message you are getting indicates that you a code block isn't being ended properly (with use of the end keyword). There are a couple of other issues too. Try this

Code:
if rs,getInput("left") == true then -- then and if must not be capitalised
shell.run(name) -- shell.run is probably more suitable for your purposes if all you want to do is make a program run
else
print("flip the lever")
end -- this end must come at the end of the if/else statement (aka conditional) to close the code block. A conditional is a type of code block by the way but that is just some jargon you don't need to worry about too much just yet

Also this program will stop not do run the target program even if you flip the lever. If that is intended then fine, but you will need something called a while loop and a redstone event otherwise (its pretty easy though so feel free to ask if you want help).

Edit: Arkandos you mind reading ninja you!
 

DZCreeper

New Member
Jul 29, 2019
1,469
0
1
Code:
while true do
    if rs.getInput("left") then
        shell.run("program")
    else
        print("Flip Lever")
        sleep(5)
    end
end

This is what you want most likely. Constantly runs in a loop and when it gets the redstone signal it swaps to the program you want. When its not, every 5 seconds it will check again and print your message.
 

trajing

New Member
Jul 29, 2019
3,091
-14
1
Code:
while true do
    if rs.getInput("left") then
        shell.run("program")
    else
        print("Flip Lever")
        sleep(5)
    end
end

This is what you want most likely. Constantly runs in a loop and when it gets the redstone signal it swaps to the program you want. When its not, every 5 seconds it will check again and print your message.
Better yet, corotines.
 

Feed the beast 122

New Member
Jul 29, 2019
101
0
0
Ok dz creeper did that and when i flip the switch off how do i get to unprint what it says on the monitor or do i just do a monitor.clear() in the code? (Side note what you said worked and i'm using that to make a statup code for it.) Thanks
 

trajing

New Member
Jul 29, 2019
3,091
-14
1
*code ninja dissapears in cloud of functions*



Why would you use corotines for something this simple? Not really necessary unless you want to run 2 complicated programs at once.
I use corotines for everything. Kinda obsessed with them.