15 posts
Location
Pacific Northwest
Posted 29 November 2017 - 04:44 AM
so ive been having a bit of an issue. i posted a video that goes over it in better detail, but short story is i made a program that is two progress bars that monitor how much power i am storing and producing. if i used a while true do loop, it seemed like the progress bars wouldnt update, so i have the program reboot the computer at the end of the script, which i think creates a "glitch" or moment where the screen is blank while the computer reboots.
it also randomly stops displaying on the monitor and terminal, but i dont belive it shuts off or anything as i can still terminate the program with ctrl+t
im pretty noob to coding, but i could def use some advice!!
links to youtube vid:
https://youtu.be/FlvUA4s6i28my script after making several messy changes:
https://pastebin.com/3CJvSprioriginal script i found online before my changes:
https://pastebin.com/jdygeyxx
2427 posts
Location
UK
Posted 29 November 2017 - 05:53 PM
use a while true loop, make sure that line 7 is in the loop but line 8 is not (you will have to move line 7)
you'll want your loop to start at line 55, and finish at 77
15 posts
Location
Pacific Northwest
Posted 30 November 2017 - 05:39 AM
alright, i had that nearly once before. sounds like i just need to have my "curpull" referrance in the loop basically… so I put that up top thinking that when the program got to the loop, it would know what i meant by curpull. if you have time, can you explain why it needs to be in the loop? also made the changes you recommened, of course the loop fixed my randomly ending issue, but i still had a flicker on the screen, which i corrected by getting ride of the mon.clear() at the begining of the loop. seems to be working fine and flickerless now. thanks for the help!!
2427 posts
Location
UK
Posted 30 November 2017 - 11:18 AM
sounds like i just need to have my "curpull" referrance in the loop basically… so I put that up top thinking that when the program got to the loop, it would know what i meant by curpull.
In the code you posted, the program knew what
curpull was but the value of
curpull never changed. By placing it in the loop the value is updated every time the loop runs.
For optimisation you may want to declare
curpull before the loop and assign it in the loop. See below (I'm not writting out the full code, I'm using comments as placeholders):
--# bind your peripherals to variables
--# function declarations (P.S functions can be made local too, you may want to google "scope lua tutoral"
--# local function clear()
--# mon.setBackgroundColor(colors.black)
--# mon.clear()
--# mon.setCursorPos(1,1)
--# end
local curpull
while true do
curpull = --# whatever you had originally being assigned
--# rest of the loop
end
Edited on 30 November 2017 - 08:09 PM
15 posts
Location
Pacific Northwest
Posted 30 November 2017 - 04:57 PM
gotcha… hence my first few attempts at not updating the changes in power… thanks,i appreate it!