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

Program "Hangs"

Started by Scorp, 16 July 2015 - 10:45 AM
Scorp #1
Posted 16 July 2015 - 12:45 PM
I am trying to make a program that will allow me to make changes to my reactor by touching the screen. The program does what I want it to do with only one problem. I added the os.pullEvent(monitor_touch), so I could have "buttons" for the adjustments, but now the program just hangs up until I push a button. How can I make it so the program keeps looping regardless if I push one of my buttons or not?

Here is my code: http://pastebin.com/1x7TBqXP

Thanks for any and all help :)/>

~Scorp

Edit: Also thought I should include: If I click on the monitor (not in the locations of the buttons) it refreshes all values like it should. But only if I click it.
Edited on 16 July 2015 - 10:47 AM
InDieTasten #2
Posted 16 July 2015 - 12:57 PM

local timer = os.startTimer(1)
while (true) do
local event,a,b,c,d = os.pullEvent()
if(event == "monitor_touch") then
--#button code
elseif(event == "timer" and a == timer) then
--#loop code
timer = os.startTimer(1) --#one being the interval
end
end
Edited on 16 July 2015 - 10:57 AM
Scorp #3
Posted 16 July 2015 - 01:07 PM
Awesome! Thank you so much. Works Perfect :D/>
Balthamel #4
Posted 17 July 2015 - 02:53 AM
Why do you have line 16 to 71 writing blank spaces all over the screen when monitor.clear() will blank it.
put set background color before monitor clear and then it will clear the monitor to that background colour.

running your pull event to a predifined number of varibles is very limiting and could throw errors later, I personally use
local eventQueue = os.pullEvent()

with this eventQueue[1] is the same as your variable a, eventQueue[2] i the same as x and so on up to as many variables as the event may return (i believe the max is 6)


random best practive rubbish
localise all variables and functions by putting local in front of them when they are fist used.
for safety if a variable is first declared inside a loop or function call but still required outside the loop declare ALL variables at the top of the code, 20 lines of all your varaibals going
local x,y,z
local derp
and so on is just fine.

please use more comments it makes it so much easier to help you if i can glance at comments to see what you're trying to do on and given line.