17 posts
Posted 23 January 2015 - 09:24 PM
It's a weird problem with a program I am trying to create. I wouldn't call myself a noob at computercraft, I know the basics. I just don't see what's wrong. The error code is "Bios:206: [string "Startup"]:5: 'then' expected. The code goes like this:
term.clear()
term.setCursorPos(1,1)
write("Door Control Computer.")
if rs.Input("bottom", true) then
redpulse("right", 8)
sleep(3)
(I then repeat the redpulse and sleep 4 times and end the function)
I know what the error code is trying to tell me. I just don't see where i'm missing the then. Sorry for being a N008. Thanks for the help. Greatly appreciated! :)/>
113 posts
Location
This page
Posted 23 January 2015 - 10:21 PM
I copied the code and tried it myself, I did not get a 'then' expected error, However I do notice a few things
1. I believe you want rs.getInput() not rs.Input() and it would not have the true, it would just be
rs.getInput("bottom")
2. You could use print instead of write so it goes to the next line (unless you plan to draw this to a monitor at some point)
3. Unless you have a function called redpulse(), it is not going to work, redpulse is a file in the computercraft rom, not a function
You could make it a function by adding this to your code (at a point before you call redpulse)
local function redpulse(side,count,speed)
if speed==nil then speed=0.25 end
for x=1,count do
rs.setOutput(side,true)
sleep(speed)
rs.setOutput(side,false)
sleep(speed)
end
end
113 posts
Location
This page
Posted 23 January 2015 - 10:27 PM
Also since you say you do
redpulse("right", 8)
sleep(3)
4 more times you could put that in a loop
After all changes are made you code would work like this
local function redpulse(side,count,speed)
if speed==nil then speed=0.25 end
for x=1,count do
rs.setOutput(side,true)
sleep(speed)
rs.setOutput(side,false)
sleep(speed)
end
end
term.clear()
term.setCursorPos(1,1)
term.write("Door Control Computer.")
if rs.getInput("bottom") then
for x=1,5 do
redpulse("right", 8)
sleep(3)
end
end
Edited on 23 January 2015 - 09:33 PM
17 posts
Posted 23 January 2015 - 10:35 PM
Thank you. :)/>
17 posts
Posted 23 January 2015 - 10:53 PM
I'm really sorry to have to bother you again but is there anyway I can make this pulse to different sides not just one? Thank you though the code works! :)/>
Edit: Worked it out, it's going to be a long process but I'll manage thanks! ;)/>
Edited on 23 January 2015 - 10:07 PM
113 posts
Location
This page
Posted 23 January 2015 - 11:33 PM
local function redpulse(side,count,speed)
if speed==nil then speed=0.25 end
if type(side)=="string" then
for x=1,count do
rs.setOutput(side,true)
sleep(speed)
rs.setOutput(side,false)
sleep(speed)
end
elseif type(side)=="table" then
for x=1,count do
for _,s in pairs(side) do
rs.setOutput(s,true)
end
sleep(speed)
for _,s in pairs(side) do
rs.setOutput(s,false)
end
sleep(speed)
end
end
end
The first parameter can be either a string side, ex: "left" or "top" or it can be a table, ex: {"left","right","top"}
When it is a table all the sides in the table will pulse at the same time.
17 posts
Posted 24 January 2015 - 10:49 PM
Hello, back again. Thought I'd put this here rather than creating a new topic. So, i've made my program and it works except for one thing: when there is no Redstone pulse in the bottom it ends the program. I want to make it so if there isn't a Redstone pulse that it will keep restarting the program every few seconds. Any idea how I could do this?
113 posts
Location
This page
Posted 24 January 2015 - 11:02 PM
You would put the check into a loop
Change this
if rs.getInput("bottom") then
for x=1,5 do
redpulse("right", 8)
sleep(3)
end
end
to this
while true do
os.pullEvent("redstone") --Waits for the redstone input on any side to change
if rs.getInput("bottom") then
for x=1,5 do
redpulse("right", 8)
sleep(3)
end
end
end
Edited on 24 January 2015 - 10:26 PM
17 posts
Posted 24 January 2015 - 11:34 PM
Thanks!
17 posts
Posted 25 January 2015 - 11:17 AM
Ok, i'm back again. This time the program just doesn't work and I don't know why. I haven't added in the code above yet and I tested it yesterday, it worked fine. Now it saying that eof is expected even though yesterday this didn't happen and i've made no changes since.
Edit: Fixed it!
Edit: The code you gave me doesn't work. I've spent 20 mins looking for the unexpected symbol error and I can't find it! The program ran and worked before I put this in.
Edited on 25 January 2015 - 10:44 AM
7083 posts
Location
Tasmania (AU)
Posted 25 January 2015 - 11:21 AM
EOF = End Of File. The Lua interpreter would expect the file to end if you put in and "end" statement somewhere that doesn't have a matching if/for/whatever statement above it. If you put more code after such an "end", then it realises you must've made a mistake, and so it errors out.
17 posts
Posted 25 January 2015 - 02:33 PM
Thank you. I've corrected that but now it saying there is an unexpected symbol. I've looked where I put the new code in but I can't see it and it can't be one of the lines before this new code was put in because it worked fine then. Help!
113 posts
Location
This page
Posted 25 January 2015 - 07:13 PM
Do to all the changes that have been made to it, could you please post the code as it is now?
17 posts
Posted 26 January 2015 - 08:50 PM
I'm really sorry that I haven't been able to answer your reply properly. My internet's gone to @?£%%^&*R%$%&I* right now and I've encountered a problem with tekkit where all the blocks i've placed turn up invisible and the game acts as if they're not there. I'm waiting for a reply from the tekkit forum people thingys. Really sorry!