236 posts
Posted 15 September 2013 - 07:43 AM
term.clear()
os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
DesignUtil.setDesign("whiteLightGray")
local backGround,topBar=DesignUtil.getDesign()
local drawO1=false;
term.setTextColor(colors.black)
local O1B=
{
text="O1|";
x=1;
y=1;
W=math.ceil(3);
H=math.ceil(1);
}
local O1Menu =
{
line1text="About this device";
line1x=1;
line1y=2;
line1W=18;
line1H=1
}
function drawO1Menu()
while drawO1==true do
term.setCursorPos(O1Menu.line1x,O1Menu.line1y)
print(O1Menu.line1text)
sleep(0.15)
end
end
function registerClick(x,y)
if x > O1B.x and x < O1B.x + O1B.w - 1 and y > O1B.y and y < O1B.y + O1B.h then
drawO1=not drawO1
end
end
while true do
paintutils.drawImage(backGround,1,1)
paintutils.drawImage(topBar,1,1)
term.setCursorPos(1,1)
print(O1B.text)
event, button, xPos, yPos = os.pullEvent("mouse_click")
print(x..y)
registerClick(xPos,yPos)
drawO1Menu()
sleep(0.15)
end
heres the code, the problem is that registerClick OR drawO1Menu are not working somehow, when I click on the text, the menu wont be drawn. What is the issue & how to fix?
1140 posts
Location
Kaunas, Lithuania
Posted 15 September 2013 - 08:42 AM
2 tips:
W=math.ceil(3);
H=math.ceil(1);
--//It is the same as:
W=3
H=1
--//math.ceil(x) returns highest nearest integer or x if x is already an integer
print(x..y)
--//This will error because x and y are not set
Your problem is here:
function registerClick (x, y)
if x > O1B.x and x < O1B.x + O1B.w - 1 and y > O1B.y and y < O1B.y + O1B.h then
drawO1=not drawO1
end
end
--//When you check y position you check if you clicked BELOW your button (y > O1B.y). In fact you do same thing with x and other checks. What you should do is change all ">" to ">=" and "<" to "<=":
function registerClick (x, y)
if x >= O1B.x and x <= O1B.x + O1B.w - 1 and y >= O1B.y and y <= O1B.y + O1B.h then
drawO1=not drawO1
end
end
--//This is because you want to check if y is BELOW OR EQUAL to your button's start y position; same with all other checks.
236 posts
Posted 15 September 2013 - 09:24 AM
Did that and it sure didn`t work…
1522 posts
Location
The Netherlands
Posted 15 September 2013 - 09:36 AM
You never invoke a function
I thought you meant something else..
Technically it should work, but this is useless crap Im giving you
236 posts
Posted 15 September 2013 - 09:39 AM
the function registerClick is supposed to set a variable that is used by the drawing function that is constantly invoked by the while true do loop.. apparently manually setting tha value aint drawingit either….
edit: it is, current code:
term.clear()
os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
DesignUtil.setDesign("whiteLightGray")
local backGround,topBar=DesignUtil.getDesign()
local drawO1=true;
term.setTextColor(colors.black)
local O1B=
{
text="O1|";
x=1;
y=1;
W=3;
H=1;
}
local O1Menu =
{
line1text="About this device";
line1x=1;
line1y=2;
line1W=18;
line1H=1
}
function drawO1Menu()
while drawO1 do
term.setCursorPos(O1Menu.line1x,O1Menu.line1y)
print(O1Menu.line1text)
sleep(0.15)
end
end
function registerClick (x, y)
if x >= O1B.x and x <= O1B.x + O1B.w - 1 and y >= O1B.y and y <= O1B.y + O1B.h then
drawO1= not drawO1
end
end
while true do
paintutils.drawImage(backGround,1,1)
paintutils.drawImage(topBar,1,1)
term.setCursorPos(O1B.x,O1B.y)
print(O1B.text)
drawO1Menu()
event, button, xPos, yPos = os.pullEvent("mouse_click")
registerClick(xPos,yPos)
sleep(0.15)
end
the clicking part still aint working
1140 posts
Location
Kaunas, Lithuania
Posted 15 September 2013 - 10:03 AM
Found another issue:
O1B.y + O1B.h
O1B.x + O1B.w
--//Should be:
O1B.y + O1B.H
O1B.x + O1B.W
EDIT:
Did you get any error?
236 posts
Posted 15 September 2013 - 10:22 AM
worked, however.. the menu is drawn and a few sec later its removed from screen…. need to undo that and my own reclick on O1| is not removing the menu
current code
term.clear()
os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
DesignUtil.setDesign("whiteLightGray")
local backGround,topBar=DesignUtil.getDesign()
local drawO1=false;
term.setTextColor(colors.black)
local O1B=
{
text="O1|";
x=1;
y=1;
W=3;
H=1;
}
local O1Menu =
{
line1text="About this device";
line1x=1;
line1y=2;
line1W=18;
line1H=1
}
function drawO1Menu()
while drawO1 do
term.setCursorPos(O1Menu.line1x,O1Menu.line1y)
print(O1Menu.line1text)
end
end
function registerClick (x, y)
if x >= O1B.x and x <= O1B.x + O1B.W - 1 and y >= O1B.y and y <= O1B.y + O1B.H then
drawO1= not drawO1
end
end
while true do
paintutils.drawImage(backGround,1,1)
paintutils.drawImage(topBar,1,1)
term.setCursorPos(O1B.x,O1B.y)
print(O1B.text)
drawO1Menu()
event, button, xPos, yPos = os.pullEvent("mouse_click")
registerClick(xPos,yPos)
sleep(0.15)
end
1190 posts
Location
RHIT
Posted 15 September 2013 - 11:46 AM
Please refrain from bumping if it's been less than a few days.
Why does your draw01menu function have a while loop in it? You should remove that while loop.
Change it to something like this instead:
function drawO1Menu()
if draw01 then
term.setCursorPos(O1Menu.line1x,O1Menu.line1y)
print(O1Menu.line1text)
end
end
236 posts
Posted 15 September 2013 - 11:52 AM
That just made the thing not work at all,
cureent code
term.clear()
os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
DesignUtil.setDesign("whiteLightGray")
local backGround,topBar=DesignUtil.getDesign()
local drawO1=true;
print(window)
term.setTextColor(colors.black)
local O1B=
{
text="O1|";
x=1;
y=1;
W=3;
H=1;
}
local O1Menu =
{
line1text="About this device";
line1x=1;
line1y=2;
line1W=18;
line1H=1
}
function drawO1Menu()
if draw01 then
term.setCursorPos(O1Menu.line1x,O1Menu.line1y)
print(O1Menu.line1text)
end
end
function registerClick (x, y)
if x >= O1B.x and x <= O1B.x + O1B.W - 1 and y >= O1B.y and y <= O1B.y + O1B.H then
drawO1=true
end
end
while true do
paintutils.drawImage(backGround,1,1)
paintutils.drawImage(topBar,1,1)
term.setBackgroundColor(colors.lightGray)
term.setCursorPos(O1B.x,O1B.y)
print(O1B.text)
drawO1Menu()
event, button, xPos, yPos = os.pullEvent("mouse_click")
registerClick(xPos,yPos)
sleep(0.1)
end
I click-nothing happens
1190 posts
Location
RHIT
Posted 15 September 2013 - 12:06 PM
You don't set draw01 to false, you set it to true in the registerClick function. It needs to change to false if you don't want the menu displayed.
Change that to this:
function registerClick (x, y)
if x >= O1B.x and x <= O1B.x + O1B.W - 1 and y >= O1B.y and y <= O1B.y + O1B.H then
drawO1=false
end
end
You should probably also clear the screen during every while loop unless those images take the entire screen. Otherwise it will look like the menu hasn't disappeared despite not being redrawn.
130 posts
Posted 15 September 2013 - 12:06 PM
When you click on O1B it sets draw01 to true, which since draw01 is already true does nothing. I'm guessing what you want is:
draw01 = not draw01
Also you don't need a sleep in your main loop.
236 posts
Posted 15 September 2013 - 12:08 PM
all works now, final code
term.clear()
os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
DesignUtil.setDesign("whiteLightGray")
local backGround,topBar=DesignUtil.getDesign()
local drawO1=false;
print(window)
term.setTextColor(colors.black)
local O1B=
{
text="O1|";
x=1;
y=1;
W=3;
H=1;
}
local O1Menu =
{
line1text="About this device";
line1x=1;
line1y=2;
line1W=18;
line1H=1
}
function drawO1Menu()
if draw01 then
term.setCursorPos(O1Menu.line1x,O1Menu.line1y)
print(O1Menu.line1text)
end
end
function registerClick (x, y)
if x >= O1B.x and x <= O1B.x + O1B.W - 1 and y >= O1B.y and y <= O1B.y + O1B.H then
draw01 = not draw01
end
end
while true do
paintutils.drawImage(backGround,1,1)
paintutils.drawImage(topBar,1,1)
term.setBackgroundColor(colors.lightGray)
term.setCursorPos(O1B.x,O1B.y)
print(O1B.text)
drawO1Menu()
event, button, xPos, yPos = os.pullEvent("mouse_click")
registerClick(xPos,yPos)
sleep(0.1)
end