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

Mouse Click Flicker-How To Remove?

Started by makerimages, 21 September 2013 - 04:46 AM
makerimages #1
Posted 21 September 2013 - 06:46 AM
How can I remove the print statement flicker when I click the mouse? a sleep statement somewhere?

code(Delicate bits ab my project x-ed out)


os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
os.loadAPI("Apis/windowSystem")
DesignUtil.setDesign("whiteLightGray")
local background,topBar =DesignUtil.getDesign()
local window =windowSystem.createWindow("xxxxxxxxxxxx",2,2,48,16,false)
local iHave={
text="xxxxxxxxxxx";
x=48/2-6;
y=5;
W=18;
H=1;
}
function registerClick(x,y)

end
while true do
paintutils.drawImage(background,1,1)
windowSystem.drawWindow(window)
term.setBackgroundColor(colors.white)
term.setCursorPos(iHave.x,iHave.y)
print(iHave.text)

   event, button, xPos, yPos = os.pullEvent("mouse_click")
   registerClick(xPos,yPos)
end

kreezxil #2
Posted 21 September 2013 - 07:02 AM
Yes, you are right!

Right after the print that vanishes or flickers put
os.sleep(1)
makerimages #3
Posted 21 September 2013 - 07:26 AM
that makes every second click flicker…
kreezxil #4
Posted 21 September 2013 - 07:44 AM
In order to help you further we'll need a pastebin to all of your code including the private bits with the xxx's. There is clearly something else happening over and above what your snippet indicates.
makerimages #5
Posted 21 September 2013 - 07:53 AM

os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
os.loadAPI("Apis/windowSystem")
DesignUtil.setDesign("whiteLightGray")
local background,topBar =DesignUtil.getDesign()
local window =windowSystem.createWindow("xxxxxx",2,2,48,16,false)
local iHave={
text="xxxxxxx";
x=48/2-6;
y=5;
W=18;
H=1;
}
function registerClick(x,y)
   if x >= iHave.x and x <= iHave.x + iHave.W - 1 and y >= iHave.y and y <=  iHave.y + iHave.H then
	shell.run("xxx")
   end
end
while true do
paintutils.drawImage(background,1,1)
windowSystem.drawWindow(window)
term.setBackgroundColor(colors.white)
term.setCursorPos(iHave.x,iHave.y)
print(iHave.text)

   event, button, xPos, yPos = os.pullEvent("mouse_click")
   registerClick(xPos,yPos)
end

Edit: amoun tof "x"-s in the iHave.text is not right, it should be as many x-s as W is in the table

this is all, the x strings are some that will easily give away what im working on, just text, nothing else
kreezxil #6
Posted 21 September 2013 - 10:02 AM
what about those apis? where do we get them?
kreezxil #7
Posted 21 September 2013 - 10:05 AM
these two lines of code seem like they could be the source of the flicker

paintutils.drawImage(background,1,1)
and

term.setBackgroundColor(colors.white)
makerimages #8
Posted 21 September 2013 - 10:14 AM
The apis are:
designutils

local fileColorConfig=nil
local topBar=nil
local backGround=nil

local fileData = {}

function getDesign()

fileColorConfig=fs.open("data/colorCombos/current","r");
local line = fileColorConfig.readLine()
repeat
table.insert(fileData,line)
line = fileColorConfig.readLine()
until line == nil
fileColorConfig.close()
local fileColorSetting=fs.open("data/colorCombos/"..fileData[1],"r");

local fileDataSetting = {}
local lineSetting = fileColorSetting.readLine()
repeat
table.insert(fileDataSetting,lineSetting)
lineSetting = fileColorSetting.readLine()
until lineSetting == nil
fileColorSetting.close()
if fileDataSetting[1]=="0" then backGround=paintutils.loadImage("graphics/backgrounds/whiteBack.nfp") end
if fileDataSetting[1]=="1" then backGround=paintutils.loadImage("graphics/backgrounds/orangeBack.nfp") end
if fileDataSetting[1]=="2" then backGround=paintutils.loadImage("graphics/backgrounds/darkPinkBack.nfp") end
if fileDataSetting[1]=="3" then backGround=paintutils.loadImage("graphics/backgrounds/lightBlueBack.nfp") end
if fileDataSetting[1]=="4" then backGround=paintutils.loadImage("graphics/backgrounds/goldenBack.nfp") end
if fileDataSetting[1]=="5" then backGround=paintutils.loadImage("graphics/backgrounds/limeBack.nfp") end
if fileDataSetting[1]=="6" then backGround=paintutils.loadImage("graphics/backgrounds/pinkBack.nfp") end
if fileDataSetting[1]=="7" then backGround=paintutils.loadImage("graphics/backgrounds/grayBack.nfp") end
if fileDataSetting[1]=="9" then backGround=paintutils.loadImage("graphics/backgrounds/cyanBack.nfp") end --because 8 is topbar color
if fileDataSetting[1]=="a" then backGround=paintutils.loadImage("graphics/backgrounds/purpleBack.nfp") end
if fileDataSetting[1]=="b" then backGround=paintutils.loadImage("graphics/backgrounds/blueBack.nfp") end
if fileDataSetting[1]=="c" then backGround=paintutils.loadImage("graphics/backgrounds/brownBack.nfp") end
if fileDataSetting[1]=="d" then backGround=paintutils.loadImage("graphics/backgrounds/greenBack.nfp") end
if fileDataSetting[1]=="e" then backGround=paintutils.loadImage("graphics/backgrounds/redBack.nfp") end


if fileDataSetting[2]=="8"then topBar=paintutils.loadImage("graphics/topBars/topBarLightGray.nfp") end
fileColorConfig.close()
return backGround, topBar;
end
function setDesign(design)
fileColorConfig=fs.open("data/colorCombos/current","w");
fileColorConfig.write(design)
fileColorConfig.close()
end
basically it loads a image according to numbers loaded from a file

window api:

local window=nil;
function createWindow(title,x,y,w,h,closeable)
window=
{
  titlew=title;
  x=x;
  y=y;
  W=w;
  H=h;
  ca=closeable;
}
return window
end
function drawWindow(windowp)
term.setCursorPos(window.x,window.y)
term.setBackgroundColor(colors.lightGray)
for i=0, windowp.W do
  term.setCursorPos(windowp.x+i,windowp.y)
  print(" ")
  term.setCursorPos(windowp.x+i,windowp.y+windowp.H)
  print(" ")

end
for j=0, windowp.H do
  term.setCursorPos(windowp.x,windowp.y+j)
  print(" ")
  term.setCursorPos(windowp.x+windowp.W,windowp.y+j)
  print(" ")

end
  term.setCursorPos(windowp.x+windowp.W/2-string.len(windowp.titlew)/2,windowp.y)
  term.setTextColor(colors.gray)
  print(windowp.titlew)
  if(windowp.ca) then
  
  term.setBackgroundColor(colors.red)
term.setCursorPos(windowp.x+windowp.W+1,windowp.y)
print("X")
end
sleep(0.1)

end

current program:

os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
os.loadAPI("Apis/windowSystem")
DesignUtil.setDesign("whiteLightGray")
local background,topBar =DesignUtil.getDesign()
local window =windowSystem.createWindow("Select OSOne ID identification method",2,2,48,16,false)
local iHave={
text="I have an OSOne ID";
x=48/2-6;
y=5;
W=18;
H=1;
}
function registerClick(x,y)
   if x >= iHave.x and x <= iHave.x + iHave.W - 1 and y >= iHave.y and y <=  iHave.y + iHave.H then
    shell.run("OSCore/setupCycle/haveID.stup")
   end
end
while true do
paintutils.drawImage(background,1,1)
windowSystem.drawWindow(window)
--term.setBackgroundColor(colors.white)
term.setCursorPos(iHave.x,iHave.y)
print(iHave.text)
sleep(1)
   event, button, xPos, yPos = os.pullEvent("mouse_click")
   registerClick(xPos,yPos)
end

theoriginalbit #9
Posted 21 September 2013 - 10:43 AM
Yes, you are right!

Right after the print that vanishes or flickers put
os.sleep(1)
*facepalm* no. that is not the ideal solution, one should not have to resort to a sleep in order to fix a problem, it has lots of other implications by doing it!


To avoid a flicker or screen tear you should only update changes to the screen. Carelessly redrawing GUIs is what causes flicker, as such to reduce on it you should only draw what is different. The easiest method of doing this is to make a screen buffer that acts between the terminal and your code. It should have a table containing the information about the current screen and then when code attempts to write to it, only actually pass that through to the terminal if it needs to be (i.e. its different to whats currently there)! There are a few other strategies you can add on top of this as well to reduce flicker and tearing, but the one I outlined here is the simplest.
makerimages #10
Posted 22 September 2013 - 10:32 AM
why does http://pastebin.com/XJX34S08 say on the registerClick if statement that is is trying to index ?(a number value) ?
this has worked form me earlier, but now it shows this….
LBPHacker #11
Posted 22 September 2013 - 11:20 AM
For the record, post the full error message, line number and the other APIs, please. So we can actually help.
MysticT #12
Posted 22 September 2013 - 11:21 AM
This line:

event, button, xPos, yPos = os.pullEvent("mouse_click")
is overwriting the button variable with a number (the button number from the mouse_click event).
makerimages #13
Posted 22 September 2013 - 11:24 AM
yeah, got it thanks to the IRC again
Lyqyd #14
Posted 22 September 2013 - 01:17 PM
Threads merged. Stick to one topic for all questions about a given piece of code.
makerimages #15
Posted 23 September 2013 - 10:07 AM
Hi, I have a program

os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
os.loadAPI("Apis/windowSystem")
DesignUtil.setDesign("whiteLightGray")
local background,topBar =DesignUtil.getDesign()
local showOS1Menu = false;
local routine=nil;
programCache={}
table.insert(programCache,function() shell.run("OSCore/aboutW.app") end)
function updateCache()
for i=1, #programCache,1 do
  routine=coroutine.create(programCache[i])
  ok, err=coroutine.resume(routine)
end
end

term.setTextColor(colors.gray)
function registerClickEvent(x,y)
if x >=0 and x <=1+3-1 and y >=0 and y <=1+1-1 then
  showOS1Menu= not showOS1Menu
end
end
function printOS1Menu()
if showOS1Menu then
  term.setBackgroundColor(colors.lightGray)
  term.setCursorPos(1,2)
  print("About this device")
  term.setCursorPos(1,3)
  print("Software update  ")
  term.setCursorPos(1,4)
  print("Restart device   ")
  term.setCursorPos(1,5)
  print("Shut down	    ")
end
end
while true do

paintutils.drawImage(background,1,1)
paintutils.drawImage(topBar,1,1)
updateCache()
printOS1Menu()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.lightGray)
print("O1|")
event, button, xPos, yPos = os.pullEvent("mouse_click")
registerClickEvent(xPos,yPos)
sleep(0.15)
end

which runs this program as a coroutine

os.loadAPI("Apis/windowSystem")
local afData = {}
local x,y=0;
function exit()
print(programCache[1])

end
local SysU=
{
text="Software update";
x=22;
y=7;
W=15;
H=1;
}

function loadAbout()
local abF=fs.open("data/osInfo","r")
local line = abF.readLine()
repeat
  table.insert(afData,line) -- Puts the value of the current line into the table we have.
  line = abF.readLine() -- read the next line
until line == nil -- readLine() returns nil when the end of the file is reached.
abF.close() -- Close up the file ready for use again.
end
loadAbout()
function registerClick(xPos,yPos)
shell.run("OSCore/loginUtil")
if xPos==window.x+window.W+1 and yPos==window.y then
   exit()
  end
if xPos >= SysU.x and xPos <= SysU.x + SysU.W - 1 and yPos >= SysU.y and yPos <=  SysU.y + SysU.H then
   shell.run("OSCore/updateManager.app")
  end
end
local window=windowSystem.createWindow("About this Device",21,3,18,13,true,"Version:"..afData[1].." \n \n \n System: "..afData[2])
while true do
windowSystem.drawWindow(window)
term.setBackgroundColor(colors.white)
 
local event, button, XPos, YPos=os.pullEvent("mouse_click")
	    registerClick(XPos,YPos)
  sleep(0.15)
end

It uses apis:

windowSystem:

local window=nil;
function createWindow(title,x,y,w,h,closeable,text)
window=
{
  titlew=title;
  x=x;
  y=y;
  W=w;
  H=h;
  ca=closeable;
  text=text;
}
return window
end
function drawWindow(windowp)
term.setCursorPos(window.x,window.y)
term.setBackgroundColor(colors.lightGray)
for i=0, windowp.W do
  term.setCursorPos(windowp.x+i,windowp.y)
  print(" ")
  term.setCursorPos(windowp.x+i,windowp.y+windowp.H)
  print(" ")

end
for j=0, windowp.H do
  term.setCursorPos(windowp.x,windowp.y+j)
  print(" ")
  term.setCursorPos(windowp.x+windowp.W,windowp.y+j)
  print(" ")
 
end
  term.setCursorPos(windowp.x+windowp.W/2-string.len(windowp.titlew)/2,windowp.y)
  term.setTextColor(colors.gray)
  print(windowp.titlew)
  if(windowp.ca) then
  
  term.setBackgroundColor(colors.red)
term.setCursorPos(windowp.x+windowp.W+1,windowp.y)
print("X")
term.setBackgroundColor(colors.white)
end
term.setCursorPos(windowp.x+2,windowp.y+2)

for i in string.gmatch(windowp.text,"[^\n]+") do
    print(i)
    x,y=term.getCursorPos()
    if i== " " then
	 term.setCursorPos(windowp.x+1,y)
	  end
end
sleep(0.1)
end

and DesignUtil


local fileColorConfig=nil
local topBar=nil
local backGround=nil

local fileData = {}

function getDesign()

fileColorConfig=fs.open("data/colorCombos/current","r");
local line = fileColorConfig.readLine()
repeat
table.insert(fileData,line)
line = fileColorConfig.readLine()
until line == nil
fileColorConfig.close()
local fileColorSetting=fs.open("data/colorCombos/"..fileData[1],"r");

local fileDataSetting = {}
local lineSetting = fileColorSetting.readLine()
repeat
table.insert(fileDataSetting,lineSetting)
lineSetting = fileColorSetting.readLine()
until lineSetting == nil
fileColorSetting.close()
if fileDataSetting[1]=="0" then backGround=paintutils.loadImage("graphics/backgrounds/whiteBack.nfp") end
if fileDataSetting[1]=="1" then backGround=paintutils.loadImage("graphics/backgrounds/orangeBack.nfp") end
if fileDataSetting[1]=="2" then backGround=paintutils.loadImage("graphics/backgrounds/darkPinkBack.nfp") end
if fileDataSetting[1]=="3" then backGround=paintutils.loadImage("graphics/backgrounds/lightBlueBack.nfp") end
if fileDataSetting[1]=="4" then backGround=paintutils.loadImage("graphics/backgrounds/goldenBack.nfp") end
if fileDataSetting[1]=="5" then backGround=paintutils.loadImage("graphics/backgrounds/limeBack.nfp") end
if fileDataSetting[1]=="6" then backGround=paintutils.loadImage("graphics/backgrounds/pinkBack.nfp") end
if fileDataSetting[1]=="7" then backGround=paintutils.loadImage("graphics/backgrounds/grayBack.nfp") end
if fileDataSetting[1]=="9" then backGround=paintutils.loadImage("graphics/backgrounds/cyanBack.nfp") end --because 8 is topbar color
if fileDataSetting[1]=="a" then backGround=paintutils.loadImage("graphics/backgrounds/purpleBack.nfp") end
if fileDataSetting[1]=="b" then backGround=paintutils.loadImage("graphics/backgrounds/blueBack.nfp") end
if fileDataSetting[1]=="c" then backGround=paintutils.loadImage("graphics/backgrounds/brownBack.nfp") end
if fileDataSetting[1]=="d" then backGround=paintutils.loadImage("graphics/backgrounds/greenBack.nfp") end
if fileDataSetting[1]=="e" then backGround=paintutils.loadImage("graphics/backgrounds/redBack.nfp") end


if fileDataSetting[2]=="8"then topBar=paintutils.loadImage("graphics/topBars/topBarLightGray.nfp") end
fileColorConfig.close()
return backGround, topBar;
end
function setDesign(design)
fileColorConfig=fs.open("data/colorCombos/current","w");
fileColorConfig.write(design)
fileColorConfig.close()
end

What I would really like is for the coroutine program to be able to register the click and run exit(), not return control back to the program that called it, how could I do this?
LBPHacker #16
Posted 23 September 2013 - 10:17 AM
Raging.
SpoilerGAH WHY ARE YOU MAKING SEPARATE TOPICS FOR THE SAME PROGRAM?!
That's not how coroutines work. Here, have this document about them. You'll know what to do once you understand how to manage coroutines properly.
Lyqyd #17
Posted 23 September 2013 - 10:29 AM
Threads merged. If I have to do this again for you, you're going on moderator preview.

LBPHacker, use the report button instead of talking about it in a reply.
makerimages #18
Posted 23 September 2013 - 12:15 PM
Form what I saw quickly having an initial read on the doc, i could create a separate program, to handle running of coroutines and have that do click checks and pass the x and y to the routine, in coroutine.resume and have actual position check in the routine, could I?
LBPHacker #19
Posted 23 September 2013 - 12:53 PM
-snip-
Yep. If you manage the coroutines, you yield the coroutine manager as well, so you'll have the event data which you can pass to the coroutines. That means you can process that event data before passing it.
makerimages #20
Posted 23 September 2013 - 01:34 PM
brilliant, will try that out asap.

edit:you should put that doc in the tutorials section, it lacks on coroutines, if I get this working, I might write one aswell.
LBPHacker #21
Posted 23 September 2013 - 01:59 PM
-snip-
Well, gotta ask Bubba about that then - it's his tutorial, after all.
By the way, the Tutorials section is far from lacking of coroutine tutorials. True, there's less of them than of door locks, but one well made tutorial would be enough of those too.
makerimages #22
Posted 24 September 2013 - 09:00 AM
Allright, what am I missing here?

the coroutine manager


programCache={}
routineCache={}
local xPos=0
local yPos=0
table.insert(programCache,function() shell.run("OSCore/desktop",xPos,yPos)end)
local routine=nil;
function startCoroutines()
for i=1, #programCache,1 do
  routine=coroutine.create(programCache[i])
  table.insert(routineCache,routine)
  ok, err=coroutine.resume(routine)
end
end
function updateCoroutines()
for i=1, #routineCache,1 do
  if coroutine.status(routineCache[i])=="suspended" then
  ok, err=coroutine.resume(routineCache[i],xPos,yPos)
  end
end
end
startCoroutines()
while true do
event, button, xPos, yPos = os.pullEvent("mouse_click")
updateCoroutines()
end

current coroutine

local tArgs = {...}
os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
os.loadAPI("Apis/windowSystem")
DesignUtil.setDesign("whiteLightGray")
local background,topBar =DesignUtil.getDesign()
local showOS1Menu = false;
term.setTextColor(colors.gray)
if #tArgs<1 then
error("Desktop: expected mouse_click coordinates X and Y, but they were not given!")
end
function registerClickEvent(x,y)
if x >=0 and x <=1+3-1 and y >=0 and y <=1+1-1 then
  showOS1Menu= not showOS1Menu
end
end
function printOS1Menu()
if showOS1Menu then
  term.setBackgroundColor(colors.lightGray)
  term.setCursorPos(1,2)
  print("About this device")
  term.setCursorPos(1,3)
  print("Software update  ")
  term.setCursorPos(1,4)
  print("Restart device   ")
  term.setCursorPos(1,5)
  print("Shut down		")
end
end
while true do

paintutils.drawImage(background,1,1)
paintutils.drawImage(topBar,1,1)

printOS1Menu()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.lightGray)
print("O1|")


registerClickEvent(tonumber(tArgs[1]),tonumber(tArgs[2]))
sleep(1)
end

the coroutine still is not responding to clicks, what am I doing wrong still?

EDIT: besides having a sleep in there(any workarounds to not need that there?)
LBPHacker #23
Posted 24 September 2013 - 09:45 AM
what am I doing wrong still?
  • There is no code in the manager which passes the event data to the coroutines - you use a bunch of locals (xPos and yPos) but you should pass event and button as well.
  • There is no code in the coroutine which pulls a mouse_click event. The only thing which yields the coroutine is the sleep there, and that doesn't return event data.
makerimages #24
Posted 25 September 2013 - 09:23 AM
Most of the things are now working.. some are not

updated windowSystem

local window=nil;
function createWindow(title,x,y,w,h,closeable,text)
window=
{
  titlew=title;
  x=x;
  y=y;
  W=w;
  H=h;
  ca=closeable;
  text=text;
}
return window
end
function drawWindow(windowp)
term.setCursorPos(window.x,window.y)
term.setBackgroundColor(colors.lightGray)
for i=0, windowp.W do
  term.setCursorPos(windowp.x+i,windowp.y)
  print(" ")
  term.setCursorPos(windowp.x+i,windowp.y+windowp.H)
  print(" ")

end
for j=0, windowp.H do
  term.setCursorPos(windowp.x,windowp.y+j)
  print(" ")
  term.setCursorPos(windowp.x+windowp.W,windowp.y+j)
  print(" ")

end
  term.setCursorPos(windowp.x+windowp.W/2-string.len(windowp.titlew)/2,windowp.y)
  term.setTextColor(colors.gray)
  print(windowp.titlew)
  if(windowp.ca) then
  
  term.setBackgroundColor(colors.red)
term.setCursorPos(windowp.x+windowp.W+1,windowp.y)
print("X")
term.setBackgroundColor(colors.white)
end
term.setCursorPos(windowp.x+2,windowp.y+2)

for i in string.gmatch(windowp.text,"[^\n]+") do
	print(i)
	x,y=term.getCursorPos()
	if i== " " then
	 term.setCursorPos(windowp.x+1,y)
	  end
end
end

the kernel part that manages routnes(this might be what is wrong)

programCache={}
routineCache={}
local evt={}
--table.insert(programCache,function() shell.run("OSCore/desktop")end)
local routine=nil;
os.queueEvent("abc", 6, "meow")
function startCoroutines()
for i=1, #programCache,1 do
  routine=coroutine.create(programCache[i])
  table.insert(routineCache,routine)
  ok, err=coroutine.resume(routine,unpack(evt))
end
end
function updateCoroutines()
for i=1, #routineCache,1 do
  if coroutine.status(routineCache[i])=="suspended" then
  ok, err=coroutine.resume(routineCache[i],unpack(evt))
  end
end
end
function addCoroutine(functionD)
table.insert(programCache,functionD)
startCoroutines()
updateCoroutines()
end
function removeCoroutine(functionD)
for k,v in ipairs(programCache) do
  if v==functionD then
   table.remove(programCache,k)
  end
end
end
if loggedStatus then
addCoroutine(function() shell.run("OSCore/desktop")end)
end
while true do
evt={os.pullEvent()}
updateCoroutines()

end

desktop coroutine

os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
os.loadAPI("Apis/windowSystem")
DesignUtil.setDesign("whiteLightGray")
local background,topBar =DesignUtil.getDesign()
local showOS1Menu = false;

term.setTextColor(colors.gray)
local OS1MenuB={
text="O1|";
x=1;
y=1;
W=3;
H=1;
}
local OS1MenuSelections=
{
s1Text="About this device";
s1X=1;
s1Y=2;
s1W=17;
s1H=1;
s2Text="Software update  ";
s2X=1;
s2Y=3;
s2W=17;
s2H=1;
s3Text="Restart device   ";
s3X=1;
s3Y=4;
s3W=17;
s3H=1;
s4Text="Shut down		";
s4X=1;
s4Y=5;
s4W=17;
s4H=1;
}
function registerClickEvent(x,y)
if x >=OS1MenuB.x and x <=OS1MenuB.x+OS1MenuB.W-1 and y >=OS1MenuB.y and y <=OS1MenuB.y+OS1MenuB.H-1 then
  if showOS1Menu then
   showOS1Menu=false
   else
	showOS1Menu=true
   end
end
if x >=OS1MenuSelections.s1X and x <=OS1MenuSelections.s1X+OS1MenuSelections.s1W-1 and y >=OS1MenuSelections.s1Y and y <=OS1MenuSelections.s1Y+OS1MenuSelections.s1H-1 then
  addCoroutine(function() shell.run("OSCore/aboutW.app")end)
  print("added routine")

end
end
function printOS1Menu()
if showOS1Menu then
  term.setBackgroundColor(colors.lightGray)
  term.setCursorPos(OS1MenuSelections.s1X,OS1MenuSelections.s1Y)
  print(OS1MenuSelections.s1Text)
  term.setCursorPos(OS1MenuSelections.s2X,OS1MenuSelections.s2Y)
  print(OS1MenuSelections.s2Text)
  term.setCursorPos(OS1MenuSelections.s3X,OS1MenuSelections.s3Y)
  print(OS1MenuSelections.s3Text)
  term.setCursorPos(OS1MenuSelections.s3X,OS1MenuSelections.s3Y)
  print(OS1MenuSelections.s3Text)
  term.setCursorPos(OS1MenuSelections.s4X,OS1MenuSelections.s4Y)
  print(OS1MenuSelections.s4Text)


end
end
while true do
local e = {os.pullEvent()}
paintutils.drawImage(background,1,1)
paintutils.drawImage(topBar,1,1)


term.setCursorPos(OS1MenuB.x,OS1MenuB.y)
term.setBackgroundColor(colors.lightGray)
print(OS1MenuB.text)

if e[1]=="mouse_click" then
  registerClickEvent(e[3],e[4])
   printOS1Menu()
end
end

and aboutW.app coroutine

os.loadAPI("Apis/windowSystem")
local afData = {}
local x,y=0;
function exit()


end
local SysU=
{
text="Software update";
x=22;
y=7;
W=15;
H=1;
}

function loadAbout()
local abF=fs.open("data/osInfo","r")
local line = abF.readLine()
repeat
  table.insert(afData,line) -- Puts the value of the current line into the table we have.
  line = abF.readLine() -- read the next line
until line == nil -- readLine() returns nil when the end of the file is reached.
abF.close() -- Close up the file ready for use again.
end
loadAbout()
function registerClick(xPos,yPos)
shell.run("OSCore/loginUtil")
if xPos==window.x+window.W+1 and yPos==window.y then
   exit()
  end
if xPos >= SysU.x and xPos <= SysU.x + SysU.W - 1 and yPos >= SysU.y and yPos <=  SysU.y + SysU.H then
   shell.run("OSCore/updateManager.app")
  end
end
local window=windowSystem.createWindow("About this Device",21,3,18,13,true,"Version:"..afData[1].." \n \n \n System: "..afData[2])
while true do
	local e = {os.pullEvent()}
windowSystem.drawWindow(window)
term.setBackgroundColor(colors.white)

   if e[1]=="mouse_click" then
		registerClick(e[3],e[4])
	end


end

heres what Id still need to make working
  • The menu in desktop wont close if I click outside of it
  • When I add the aboutW.app coroutine, the said routine starts to flicker onscreen, displays errors: No such program and AboutW:37 attemp to index ? (a nil value) (but I pass in the x and y, dont I?)
  • After a short while: TOO LONG WITHOUT YIELDING can be briefly seen, comsole spills out java.lang.ThreadDeath
How can a I make those problems dissapear aswell?? Should I load the apis inside the handler aswell, not separately in each coroutine???
LBPHacker #25
Posted 25 September 2013 - 09:38 AM
First of all :D/> use spoilers: [spoiler]something[/spoiler] (don't copy that exactly, beacuse it won't work - type it in manually).

The problem with aboutW.app is that window is declared after the declaration of registerClick ([methinks] so Lua won't recognize window as an upvalue when it's indexed from registerClick [/methinks]). The menu is buggy because the line which would make it disappear is inside a block which executes only if you click inside the menu.
makerimages #26
Posted 26 September 2013 - 08:18 AM
the aboutW.app now looks like this
Spoiler

local afData = {}
function exit()


end
local SysU=
{
text="Software update";
x=22;
y=7;
W=15;
H=1;
}

function loadAbout()
local abF=fs.open("data/osInfo","r")
local line = abF.readLine()
repeat
  table.insert(afData,line) -- Puts the value of the current line into the table we have.
  line = abF.readLine() -- read the next line
until line == nil -- readLine() returns nil when the end of the file is reached.
abF.close() -- Close up the file ready for use again.
end
loadAbout()
local window=windowSystem.createWindow("About this Device",21,3,18,13,true,"Version:"..afData[1].." \n \n \n System: "..afData[2])
function registerClick(xPos,yPos)
if xPos==window.x+window.W+1 and yPos==window.y then
   exit()
  end
if xPos >= SysU.x and xPos <= SysU.x + SysU.W - 1 and yPos >= SysU.y and yPos <=  SysU.y + SysU.H then
   shell.run("OSCore/updateManager.app")
  end
end

while true do
	local e = {os.pullEvent()}
windowSystem.drawWindow(window)
term.setBackgroundColor(colors.white)

   if e[1]=="mouse_click" then
		registerClick(e[3],e[4])
	end


end

  • it still flickers
  • and occasionally showes too long without yielding
  • It still shows java.lang.ThreadDeath in the console

EDIT: issue seems to be the addCoroutine method… It keeps adding multiple routines of the same thing, is there any way to stop that from happening?
LBPHacker #27
Posted 02 October 2013 - 10:23 AM
This will fix the flickering… (kernel/kernelProgramRunner)
Spoiler
programCache = {}
routineCache = {}
local evt = {}
--table.insert(programCache, function() shell.run("OSCore/desktop")end)
local routine = nil;
os.queueEvent("abc", 6, "meow")

function updateCoroutines()
    for i = 1, #routineCache, 1 do
        if coroutine.status(routineCache[i]) == "suspended" then
            ok, err = coroutine.resume(routineCache[i], unpack(evt))
        end
    end
end

function addCoroutine(functionD, ...)
    table.insert(programCache, functionD)
    routine = coroutine.create(programCache[#programCache])
    table.insert(routineCache, routine)
    ok, err = coroutine.resume(routine, ...)
end

function removeCoroutine(functionD)
    for k, v in ipairs(programCache) do
        if v == functionD then
            table.remove(programCache, k)
        end
    end
end

if loggedStatus then
    addCoroutine(function() shell.run("OSCore/desktop") end)
end

updateCoroutines()
while true do
    evt = {os.pullEvent()}
    updateCoroutines()
end
makerimages #28
Posted 03 October 2013 - 08:05 AM
Indeed it did! but.. i need to click once more after i click the button in desktop, to have the routine appear. and also, removeCoroutine wont remove the program from running… how to add those?

ACTUALLY, if I also run the updateManager app, it will allow to close routines… but not just when one is running, AND NOT in any order I want and after that, the screen sometimes flickers again on mouse cli nevermind, updatemanager not set up yet :)/>
LBPHacker #29
Posted 03 October 2013 - 09:36 AM
removeCoroutine doesn't work because you remove a function from the programCache table, not a coroutine from coroutineCache. I didn't see that earlier, but yeah, that's all.
makerimages #30
Posted 04 October 2013 - 01:13 AM
I tried

function removeCoroutine(functionD)
    for k, v in ipairs(programCache) do
	    if v == functionD then
		    table.remove(programCache, k)
		    table.remove(routineCache, k)

	    end
    end
end
wont work aswell
makerimages #31
Posted 05 October 2013 - 09:18 AM
Anything folks?