This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
albyalex96's profile picture

computer-pneumatic control

Started by albyalex96, 19 August 2016 - 01:46 PM
albyalex96 #1
Posted 19 August 2016 - 03:46 PM
hi guys :D/>
this is my first time i've been messing around with computercraft and touchscreen control. i found it really cool.
i'm creating a program which allows me to automatically turn on/off flux compressors by reading the pressure on a "pressure tube". however, i've encountered a problem: i can't get the monitor to update . In other terms i want the program to get every 2 seconds ( for example ) the amount of pressure and consider turning on/ off the generators. i want also see on the monitor the current pressure. i've tried using a " while true do " loop but i can't get it working because of a computer crash ( i mean that the advanced computer suddenly shut down ). in case of "high pressure" i want also a " restart button " which allows me to repeat the measure and eventually turn on the generators . i post the pastebin code of the program : http://pastebin.com/0MyVLQ9G. i use dw20's button api ( pastebin code of the button api : pastebin.com/99rFvRgE )
sorry for my bad english :unsure:/>

ps. i would like also having a vertical bar showing me the amount of pressure and a red horizontal line indicating the threshold.
thanks a lot :D/>
BrunoZockt #2
Posted 20 August 2016 - 04:56 PM
Hey,
I'd like to help you, but your pastebin link isn't working because the content was removed.
Please post a new link here or if your problem is solved, add a "[solved]" to the title.

And I'm new to this forum too and not sure but I think that it's only for help when you can't solve problems yourself. So first try the thing with the indicator bars out yourself, and if you don't get it done, ask for help again.

Bruno
KingofGamesYami #3
Posted 20 August 2016 - 07:14 PM
His link is broken because the forum included the period in the hyperlink. It is actually here:

http://pastebin.com/0MyVLQ9G

I can't address the problem myself because I am currently on mobile.
Lyqyd #4
Posted 20 August 2016 - 08:06 PM
I've fixed the link in the first post as well.
BrunoZockt #5
Posted 20 August 2016 - 10:49 PM
Ok, I have read me through your code and the button API and I don't know why your computer crashes, but I know how to make your screen updating the whole time.

Change your getClick() function to this:


while true do
  os.startTimer(2)  --starts a timer which stops after 2 seconds
  event, p1, p2, p3 = os.pullEvent()
  if event == "timer" then  --if 2 seconds are over go to the end of the while loop (won't leave it)
	return
  elseif event == "monitor_touch" then  --if the monitor is hit within the 2 seconds check if it was a button
	button.checkxy(p2, p3)
  end
end

And change the bottom of your code to this:

fillTable()
button.heading("Pneumatic Controlling Terminal")
getClick()

What my code actually does (hopefully) is, that it will check for the monitor being clicked (same as before) but will now refresh the monitor every 2 seconds (you can change the time) so that for example the pressure is always up-to-date. If it doesn't work please correct me.
I hope I could help you, I will test your program tomorrow and try to help you with your other ideas, if I get pneumatic craft running!

Bruno
Edited on 20 August 2016 - 09:02 PM
albyalex96 #6
Posted 21 August 2016 - 02:37 PM
Ok, I have read me through your code and the button API and I don't know why your computer crashes, but I know how to make your screen updating the whole time. Change your getClick() function to this:
 while true do os.startTimer(2) --starts a timer which stops after 2 seconds event, p1, p2, p3 = os.pullEvent() if event == "timer" then --if 2 seconds are over go to the end of the while loop (won't leave it) return elseif event == "monitor_touch" then --if the monitor is hit within the 2 seconds check if it was a button button.checkxy(p2, p3) end end
And change the bottom of your code to this:
fillTable() button.heading("Pneumatic Controlling Terminal") getClick()
What my code actually does (hopefully) is, that it will check for the monitor being clicked (same as before) but will now refresh the monitor every 2 seconds (you can change the time) so that for example the pressure is always up-to-date. If it doesn't work please correct me. I hope I could help you, I will test your program tomorrow and try to help you with your other ideas, if I get pneumatic craft running! Bruno

Bruno i've just finished trying using the code you gave me but it doesn't work: infact the program seems to crash . In other terms when i click to every single button the program closes without giving me any errrors. :angry:/>
BrunoZockt #7
Posted 21 August 2016 - 07:30 PM
Ok, I have read me through your code and the button API and I don't know why your computer crashes, but I know how to make your screen updating the whole time. Change your getClick() function to this:
 while true do os.startTimer(2) --starts a timer which stops after 2 seconds event, p1, p2, p3 = os.pullEvent() if event == "timer" then --if 2 seconds are over go to the end of the while loop (won't leave it) return elseif event == "monitor_touch" then --if the monitor is hit within the 2 seconds check if it was a button button.checkxy(p2, p3) end end
And change the bottom of your code to this:
fillTable() button.heading("Pneumatic Controlling Terminal") getClick()
What my code actually does (hopefully) is, that it will check for the monitor being clicked (same as before) but will now refresh the monitor every 2 seconds (you can change the time) so that for example the pressure is always up-to-date. If it doesn't work please correct me. I hope I could help you, I will test your program tomorrow and try to help you with your other ideas, if I get pneumatic craft running! Bruno

Bruno i've just finished trying using the code you gave me but it doesn't work: infact the program seems to crash . In other terms when i click to every single button the program closes without giving me any errrors. :angry:/>

No need to look angry :P/>
It was because of the "return", it left the while loop even I thought it shouldn't…
However I fixed it so it the getClick() function now looks like this:


while true do
  local id = os.startTimer(2)
  event, p1, p2, p3 = os.pullEvent()
  if event == "timer" and p1 == id then
    
  elseif event == "monitor_touch" then
    button.checkxy(p2, p3)
  else
    os.pullEvent("timer")
  end
end

And just a short thing: There is a small chance, that the monitor misses when it gets clicked. When you turn the update time down (for example 5 seconds) the chance decreases, if you turn the update time up (for example 0.1 second) the chance increases. That's because while the monitor refreshes it can't take clicks, but an update time of 1-2 seconds should work quite well)
I don't have any time to help you with the other things for now, so maybe try it out for yourself…

Bruno
albyalex96 #8
Posted 22 August 2016 - 06:40 AM
Ok, I have read me through your code and the button API and I don't know why your computer crashes, but I know how to make your screen updating the whole time. Change your getClick() function to this:
 while true do os.startTimer(2) --starts a timer which stops after 2 seconds event, p1, p2, p3 = os.pullEvent() if event == "timer" then --if 2 seconds are over go to the end of the while loop (won't leave it) return elseif event == "monitor_touch" then --if the monitor is hit within the 2 seconds check if it was a button button.checkxy(p2, p3) end end
And change the bottom of your code to this:
fillTable() button.heading("Pneumatic Controlling Terminal") getClick()
What my code actually does (hopefully) is, that it will check for the monitor being clicked (same as before) but will now refresh the monitor every 2 seconds (you can change the time) so that for example the pressure is always up-to-date. If it doesn't work please correct me. I hope I could help you, I will test your program tomorrow and try to help you with your other ideas, if I get pneumatic craft running! Bruno

Bruno i've just finished trying using the code you gave me but it doesn't work: infact the program seems to crash . In other terms when i click to every single button the program closes without giving me any errrors. :angry:/>

No need to look angry :P/>
It was because of the "return", it left the while loop even I thought it shouldn't…
However I fixed it so it the getClick() function now looks like this:


while true do
  local id = os.startTimer(2)
  event, p1, p2, p3 = os.pullEvent()
  if event == "timer" and p1 == id then
	
  elseif event == "monitor_touch" then
	button.checkxy(p2, p3)
  else
	os.pullEvent("timer")
  end
end

And just a short thing: There is a small chance, that the monitor misses when it gets clicked. When you turn the update time down (for example 5 seconds) the chance decreases, if you turn the update time up (for example 0.1 second) the chance increases. That's because while the monitor refreshes it can't take clicks, but an update time of 1-2 seconds should work quite well)
I don't have any time to help you with the other things for now, so maybe try it out for yourself…

Bruno


bruno i've just finished writing your code but it doesn't work . now when i click to the button ( "info", or "auto") the computer returns me an error to the button api . it says : button:77: attempt to compare nil with number.
the line 77 of the button api is the function checkxy
BrunoZockt #9
Posted 26 August 2016 - 10:44 PM
Ok, I have read me through your code and the button API and I don't know why your computer crashes, but I know how to make your screen updating the whole time. Change your getClick() function to this:
 while true do os.startTimer(2) --starts a timer which stops after 2 seconds event, p1, p2, p3 = os.pullEvent() if event == "timer" then --if 2 seconds are over go to the end of the while loop (won't leave it) return elseif event == "monitor_touch" then --if the monitor is hit within the 2 seconds check if it was a button button.checkxy(p2, p3) end end
And change the bottom of your code to this:
fillTable() button.heading("Pneumatic Controlling Terminal") getClick()
What my code actually does (hopefully) is, that it will check for the monitor being clicked (same as before) but will now refresh the monitor every 2 seconds (you can change the time) so that for example the pressure is always up-to-date. If it doesn't work please correct me. I hope I could help you, I will test your program tomorrow and try to help you with your other ideas, if I get pneumatic craft running! Bruno

Bruno i've just finished trying using the code you gave me but it doesn't work: infact the program seems to crash . In other terms when i click to every single button the program closes without giving me any errrors. :angry:/>

No need to look angry :P/>
It was because of the "return", it left the while loop even I thought it shouldn't…
However I fixed it so it the getClick() function now looks like this:


while true do
  local id = os.startTimer(2)
  event, p1, p2, p3 = os.pullEvent()
  if event == "timer" and p1 == id then
	
  elseif event == "monitor_touch" then
	button.checkxy(p2, p3)
  else
	os.pullEvent("timer")
  end
end

And just a short thing: There is a small chance, that the monitor misses when it gets clicked. When you turn the update time down (for example 5 seconds) the chance decreases, if you turn the update time up (for example 0.1 second) the chance increases. That's because while the monitor refreshes it can't take clicks, but an update time of 1-2 seconds should work quite well)
I don't have any time to help you with the other things for now, so maybe try it out for yourself…

Bruno


bruno i've just finished writing your code but it doesn't work . now when i click to the button ( "info", or "auto") the computer returns me an error to the button api . it says : button:77: attempt to compare nil with number.
the line 77 of the button api is the function checkxy

My Code works perfectly, but the rest of yours doesn't…
I needed a lot of time to find this mistake because I thought it was with my Code as it appears at line 77 in the button API, which gets executed by my code…
But the mistake was in your backbutton() function. That's why it only appeared when clicking "info" or "auto" cause then this function gets called.
In the last line of the backbutton() function you wrote:
button.checkxy(x, y)
This makes no sense, because first of all you didn't define x or y so they are nil values, what causes in the Error:
button:77: attempt to compare nil with number

and aside from that it wouldn't even make sense, if you have them defined because thats what your getClick() function and the while loop is for.
So I don't know why you wrote that line, simply remove it and your code works.

If you encounter any other problem, ask for help in this thread (because I already know your program and the button API) and I will help you!
Good luck ;)/>

Bruno
Edited on 26 August 2016 - 08:46 PM