2 posts
Posted 28 November 2013 - 12:27 PM
Hello! I have been making an Underground Railway based on the London Underground for a week or so now, and now I have been working on a way to stop trains using Railcraft detectors and the basic Computer.
But seemed to have come across a bit of a snag in that, when I run the program on startup it fails to do what I intended and then crashes the computer. I am very new to LUA but I can't seem to see anything wrong, any ideas?
while true do
if redstone.getInput("back",true) then
redstone.setOutput("top",false)
sleep(35)
print("Departed")
else redstone.setOutput("top",true)
end
end
7 posts
Posted 28 November 2013 - 12:51 PM
Hello! I have been making an Underground Railway based on the London Underground for a week or so now, and now I have been working on a way to stop trains using Railcraft detectors and the basic Computer.
But seemed to have come across a bit of a snag in that, when I run the program on startup it fails to do what I intended and then crashes the computer. I am very new to LUA but I can't seem to see anything wrong, any ideas?
while true do
if redstone.getInput("back",true) then
redstone.setOutput("top",false)
sleep(35)
print("Departed")
else redstone.setOutput("top",true)
end
end
Do you receive any error messages in the terminal at all? Also tell me your set up, like what is being powered and what is happening and ile see if I can make something to help :P/>
7 posts
Posted 28 November 2013 - 01:09 PM
Hello! I have been making an Underground Railway based on the London Underground for a week or so now, and now I have been working on a way to stop trains using Railcraft detectors and the basic Computer.
But seemed to have come across a bit of a snag in that, when I run the program on startup it fails to do what I intended and then crashes the computer. I am very new to LUA but I can't seem to see anything wrong, any ideas?
while true do
if redstone.getInput("back",true) then
redstone.setOutput("top",false)
sleep(35)
print("Departed")
else redstone.setOutput("top",true)
end
end
I tried the piece of code and it seemed to work fine.
I ran a track with a rail detector in the middle, and connected redstone from the detector to the back of the computer.
I then ran a piece of redstone from the top of the computer to a lamp (just for an indicator) and ran your code.
I did edit rail and pasted your code into it, and saved it.
Then I did edit startup and wrote shell.run "rail" so it runs your code when the terminal starts.
The lamp that was connected to the top of the computer stayed on, until the detector was triggered, where it then switched off, and printed "Departed" in the terminal.
Are you sure you did the startup correctly?
shell.run "Your file name"
1140 posts
Location
Kaunas, Lithuania
Posted 28 November 2013 - 02:00 PM
Are you sure you did the startup correctly?
shell.run "Your file name"
That shouldn't be the problem. He said that he got an error from that program, that means he had ran it at least once.
OP:
You are probably getting something like this:
Too long without yielding
Edited on 28 November 2013 - 07:34 PM
8 posts
Posted 28 November 2013 - 02:01 PM
I think that your program works perfect, but you had to add a thing. Cause the problem you got is probably "to long without yealding" or something like that!
the line you had to add is: sleep(0.2) or something else, so the computer can sleep a little bit.
while true do
if redstone.getInput("back",true) then
redstone.setOutput("top",false)
sleep(35)
print("Departed")
else redstone.setOutput("top",true)
end
sleep(0.2)
end
it should not get the error/crash, or interfering with the train system.
1140 posts
Location
Kaunas, Lithuania
Posted 28 November 2013 - 02:29 PM
I think that your program works perfect, but you had to add a thing. Cause the problem you got is probably "to long without yealding" or something like that!
the line you had to add is: sleep(0.2) or something else, so the computer can sleep a little bit.
while true do
if redstone.getInput("back",true) then
redstone.setOutput("top",false)
sleep(35)
print("Departed")
else redstone.setOutput("top",true)
end
sleep(0.2)
end
it should not get the error/crash, or interfering with the train system.
It would be better to use os.pullEvent("redstone") to actually wait for a redstone change. The above code should work fine but it would constantly (5 times in a second) re-run the code in the loop that on a slow computer or a slow server would lag. Also it is pointless to run the code in the loop when nothing actually happens.
2 posts
Posted 28 November 2013 - 02:40 PM
Hello! I have been making an Underground Railway based on the London Underground for a week or so now, and now I have been working on a way to stop trains using Railcraft detectors and the basic Computer.
But seemed to have come across a bit of a snag in that, when I run the program on startup it fails to do what I intended and then crashes the computer. I am very new to LUA but I can't seem to see anything wrong, any ideas?
while true do
if redstone.getInput("back",true) then
redstone.setOutput("top",false)
sleep(35)
print("Departed")
else redstone.setOutput("top",true)
end
end
Do you receive any error messages in the terminal at all? Also tell me your set up, like what is being powered and what is happening and ile see if I can make something to help :P/>/>
No error message, it simply crashed the computer and I couldn't terminate or reboot it.
331 posts
Posted 28 November 2013 - 05:24 PM
Yeh your problem is that it doesn't yield. A computer doesn't yield then other conputers cant run, the computer shuts don to allow for others to run.