function mon(disp)
m= peripheral.wrap("back")
m.write(disp)
end
--############################
function monc()
m=Peripheral.wrap("back")
m.clear()
end
--############################
function send(idnum, message)
rednet.send(idnum, message)
end
--############################
function value( messageReq)
local n= tonumber(message)
event,id, message = os.pullEvent("rednet_message")
if id==3 and messageReq ==value then
ProgressBar.SetCurValue("cap2",n)
ProgressBar.DrawToPeripheral()
else
if id==4 and messageReq==value then
ProgressBar.SetCurValue("cap1",n)
ProgressBar.DrawToPeripheral()
else
if id==3 and messageReq==max then
ProgressBar.SetMaxValue("cap2", n)
ProgressBar.DrawToPeripheral()
else
if id==4 and messageReq==max then
ProgressBar.SetMaxValue("cap1", n)
ProgressBar.DrawToPeripheral()
else
print("requirement error")
print(messageReq)
os.reboot
end
print("requirement error")
print(messageReq)
os.reboot
end
print("requirement error")
print(messageReq)
os.reboot
end
print("requirement error")
print(messageReq)
os.reboot
end
end
--############################
function isOpen()
rednet.open("right")
com = rednet.isOpen("right")
if com == true than
return true
else
return false
print("communication error")
sleep(20)
os.reboot
end
end
--############################
function isRec(idnum, messageReq)
event,id, message = os.pullEvent("rednet_message")
if id ==idnum and message== messageReq then
print("message recieved")
else
print("message error")
m.write("id")
m.write("message")
sleep(20)
os.reboot
end
end
--#######################
function cap()
while isOpen() == true then
send(4, "max")
value(max)
send(4, "value")
value(value)
send(3, "max")
value(max)
send(3, "value")
value(value)
else
print("program error")
end
end
--########################
--########################
os.loadAPI("ProgressBar")
ProgressBar.SetPeripheral("back")
ProgressBar.SetTable("cap1", 10, 1, 5,71,5)
ProgressBar.SetTable("cap2", 10, 1, 5,71,10)
ProgressBar.DrawToPeripheral()
if isOpen() == true then
send(4, "test")
isRec(4, "test")
send(3, "test")
isRec(3, "test")
cap()
else
print("communication error")
sleep(20)
os.reboot
end
if anyone can help me with this it would be appreciated.
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
syntax error need second pair of eyes
Started by kain184, 16 July 2014 - 07:05 PMPosted 16 July 2014 - 09:05 PM
hello all i am working on a program but for the life of me cant find where the error i am getting is coming from. i am loading a secondary api that i got from http://hawkee.com/snippet/10100/ to create a progress bar that will change with the power level that the two other computers i will be setting up to detect. now the problem i am getting is on line 37 says it requires a = but i cant figure out where it could be asking for that on line 37
Posted 16 July 2014 - 09:21 PM
os.reboot()
Posted 16 July 2014 - 09:23 PM
Replace 'os.reboot' with 'os.reboot()'. It is a function and has to be called as such.
Posted 16 July 2014 - 09:23 PM
os.reboot requires parentheses: os.reboot().
EDIT: Double ninja'd.
EDIT: Double ninja'd.
Edited on 16 July 2014 - 07:23 PM
Posted 16 July 2014 - 09:29 PM
that worked on that but now on line 68 says end required and from what i can see i have all the ends i should need
got that one did not like the return false if its just going to shutdown anyway
got that one did not like the return false if its just going to shutdown anyway
Edited on 16 July 2014 - 07:36 PM
Posted 16 July 2014 - 09:40 PM
Well firstly can I recommend the elseif form to you, it will improve the readability of your main control structure greatly
There is an os.reboot() fix needed in isOpen(), isRec and also your main bit
In isOpen you have an if <> than rather than then
Also of note is that you are returning false before printing, sleeping and rebooting, which means that it won't do any of those things
There is an os.reboot() fix needed in isOpen(), isRec and also your main bit
In isOpen you have an if <> than rather than then
Also of note is that you are returning false before printing, sleeping and rebooting, which means that it won't do any of those things
Posted 17 July 2014 - 02:05 AM
Lua is also case sensitive, so the above function will error with attempt to index ? (a nil value)function monc() m=Peripheral.wrap("back") m.clear() end
Posted 17 July 2014 - 02:07 AM
Also of note is that you are returning false before printing, sleeping and rebooting, which means that it won't do any of those things
This also has a side effect of throwing an error - return should always be followed by an end.
If there are further issues with ends, then indent your code properly and it might be a bit more obvious where they are.
Posted 18 July 2014 - 03:41 AM
got 90 percent of the code working but i added this as i want this system to run as backup power and having a main power shut this system off when it needs to be.
p=peripheral.wrap("top")
level=p.getEnergyStored("top")
levelm=p.getMaxEnergyStored("top")
perc=level/levelm
perct=perc*100
print(perct)
if perct < 50 then
redstone.setOutput("bottom", true)
elseif perct > 50 then
redstone.setOutput("bottom", false)
redstone.setOutput("bottom", false)
end
took your advice with the elseif code statements and it did clean it up a lot. thank you all. now i just cant find out i have tested this code over and over but i cant get it to turn the ouput off it is just stuck on for no reasonPosted 18 July 2014 - 08:36 AM
That would be because you aren't looping. try:
Which will check every 5 seconds and update the redstone as appropriate
p=peripheral.wrap("top")
while true do
--#rest of your code here
sleep(5)
end
Which will check every 5 seconds and update the redstone as appropriate
Edited on 18 July 2014 - 02:58 PM
Posted 18 July 2014 - 04:21 PM
on the actual program i have the entire code in a loop this is just the part i was having trouble with. ill go ahead and re post the entire code so you can see it in contex
as you can see the cap fuction holds a while loop and calls the main function that checks the main power input to test if it has enough power to shut off the signal. but even after the input reaches over 50 the redstone signal does not shut off.
function mon(disp)
m= peripheral.wrap("back")
m.write(disp)
end
--############################
function monc()
m=peripheral.wrap("back")
m.clear()
end
--############################
function send(idnum, message)
rednet.send(idnum, message)
end
--############################
function value( messageReq)
event,id, message = os.pullEvent("rednet_message")
print("current level")print(message)
local n= tonumber(message)
if id==3 and messageReq ==value then
ProgressBar.SetCurValue("cap2",n)
ProgressBar.DrawToPeripheral()
elseif id==6 and messageReq==value then
ProgressBar.SetCurValue("cap1",n)
ProgressBar.DrawToPeripheral()
elseif id== 3 and messageReq== max then
ProgressBar.SetMaxValue("cap2", n)
ProgressBar.DrawToPeripheral()
elseif id== 6 and messageReq== max then
ProgressBar.SetMaxValue("cap1", n)
ProgressBar.DrawToPeripheral()
else
print("requirement error")
print(messageReq)
os.reboot()
end
end
--############################
function isOpen()
rednet.open("right")
com = rednet.isOpen("right")
if com== true then
return true
else
print("communication error")
sleep(20)
os.reboot()
end
end
--############################
function isRec(idnum, messageReq)
event,id, message = os.pullEvent("rednet_message")
if id ==idnum and message== messageReq then
print("message recieved")
else
print("message error")
sleep(20)
os.reboot()
end
end
--######################
function test()
if isOpen()==true then
send(6, "test")
isRec(6, "test")
send(3, "test")
isRec(3, "test")
end
end
--#######################
function cap()
while isOpen()== true do
send(6, "max")
value(max)
send(6, "value")
value(value)
send(3, "max")
value(max)
send(3, "value")
value(value)
sleep(2)
main()
end
end
--########################
function main()
p=peripheral.wrap("top")
level=p.getEnergyStored("top")
levelm=p.getMaxEnergyStored("top")
perc=level/levelm
perct=perc*100
print(perct)
if perct < 50 then
redstone.setOutput("bottom", true)
elseif perct > 50 then
redstone.setOutput("bottom", false)
redstone.setOutput("bottom", false)
sleep(2)
end
end
--########################
os.loadAPI("/rom/apis/ProgressBar")
ProgressBar.SetPeripheral("back")
ProgressBar.SetTable("cap1", 10, 1, 5,71,5)
ProgressBar.SetTable("cap2", 10, 1, 5,71,10)
ProgressBar.DrawToPeripheral()
print("sleeping to sync")
sleep(20)
print("running")
test()
cap()
as you can see the cap fuction holds a while loop and calls the main function that checks the main power input to test if it has enough power to shut off the signal. but even after the input reaches over 50 the redstone signal does not shut off.
Posted 18 July 2014 - 05:18 PM
As a matter of style, you can stick your x=peripheral.wrap(side) declarations all together and they will persist throughout your script, you don't need to redeclare them each time you use them. Shouldn't cause issues the way you've done it, but it does look neater.
I may be being dense, but I don't see that you've actually declared the variables max and value at any point, so you are passing nil to function Value(), if you set local value="value" and local max="max" at the start of the program you should be able to test whether that's the issue
Otherwise.. what values are you getting out of your print(perct) in main() or are you never getting to that?
I may be being dense, but I don't see that you've actually declared the variables max and value at any point, so you are passing nil to function Value(), if you set local value="value" and local max="max" at the start of the program you should be able to test whether that's the issue
Otherwise.. what values are you getting out of your print(perct) in main() or are you never getting to that?
Posted 18 July 2014 - 05:45 PM
the value and max are messages sent to another computer that responds with the energy value of the capaciter banks they are attached to. but that part of the program is working fine. its the part inside the main function that is messing up and out of the main it is variable depeding on the power inside a energy block above the computer but how i have it set is to read the stored energy inside and the max from the block and make a percent. than it tests if that percent is over 50 than it should set the redstone off and if its under turn it back on. but the function never turns off and i cant figure out why.
Posted 18 July 2014 - 06:12 PM
What I am saying is that for eg:
Anyway, you need the main() function fixed. When you say that the function never turns off, what do you mean? does it run once and not return, or does it run in an infinite loop and never return to the cap function?
An easy way to test this if you are not sure would be to put 'print("returned to cap")' below calling main(), so if it does end it will print out that to let you know. The other bit of debugging information that would be useful is the value of perct, you have a print(perct) already so if you could check that the percentage does indeed change as the charge % changes then that would also be useful
send(6, "max")
value(max)
at no point have you set the value of the variable max that you are giving to the function value in the second line so you are sending nil, ie nothing. Also, worse later when you send value(value) that is never going to work because you are sending the table form of the function to itself (EDIT - technically this is wrong, you can evaluate a nil==nil and a function==function but… yeesh)Anyway, you need the main() function fixed. When you say that the function never turns off, what do you mean? does it run once and not return, or does it run in an infinite loop and never return to the cap function?
An easy way to test this if you are not sure would be to put 'print("returned to cap")' below calling main(), so if it does end it will print out that to let you know. The other bit of debugging information that would be useful is the value of perct, you have a print(perct) already so if you could check that the percentage does indeed change as the charge % changes then that would also be useful
Edited on 18 July 2014 - 04:14 PM
Posted 18 July 2014 - 09:21 PM
what the main function does is turn the value on but than it never returns and turns the function off everything else is working as the values a string message that is passed in and encoded in messagereq to tell the other computer value as the message so it will return a number value back to this computer. and that function is working as i need it to it all works. the only thing i have that is not working is the main function the perct does change and goes up and down with the power flow as i designed it but it will not turn off after but i will check to see if it is returning from cap and testing the value again but it does the print very time for perct so i would assume it has otherwise it would only give me the values from the other computers and not the next perct
Posted 19 July 2014 - 12:00 AM
found the problem it was a block update problem in a 1x1 line of redstone i needed to send the signal to a wire. made it two long and now the blocks update and change so derp on me for redstone and not the program error program is complete will be making a pastebin and uploading it for anyone who wants a copy.