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

problem with event "click"

Started by RadimBur, 18 October 2014 - 04:40 PM
RadimBur #1
Posted 18 October 2014 - 06:40 PM
Hi guys. Where is a problem please ?


local function pmenu ()
local f=fs.open("//.core/nastaveni.cfg","r")
local cnt=f.readAll()
f.close()
local nastaveni=textutils.unserialize(cnt)
term.setBackgroundColor(colors.white)
term.setTextColor(colors.black)
term.clear ()
term.setBackgroundColor(nastaveni.barva)
term.setCursorPos(1,1)
print "																							"
term.setBackgroundColor(colors.lightBlue)
term.setCursorPos(5,4)
print "- Run "
term.setCursorPos(5,6)
print "- Get "
term.setCursorPos(5,6)
print "- Put "
term.setCursorPos(5,7)
print "- End "
term.setBackgroundColor(colors.white)
while true do
local event, button, x, y = os.pullEventRaw()
if event == "mouse_click" then
if x <= 5 and x >= 10 and y == 4 and button == 1 then
spustit ()
elseif x <= 5 and x >= 10 and y == 6 and button == 1 then
ulozit ()
end
end
end
end
function spustit ()
print "vlozte kod"
kod1 = io.read ()
shell.run ("pastebin run",kod1)
end
function ulozit ()
print "vlozte kod"
kod1 = io.read ()
print "vlozte umisteni"
kod2 = io.read ()
shell.run ("pastebin get",kod1,kod2)
prohlizec ()
end
function nahrat ()
print "vlozte umisteni"
kod1 = io.read ()
shell.run ("pastebin put",kod1)
pokr = io.read ()
if pokr == "" then
pmenu ()
else
plocha ()
end
end
pmenu ()

Hi guys. Where is a problem please ?


local function pmenu ()
local f=fs.open("//.core/nastaveni.cfg","r")
local cnt=f.readAll()
f.close()
local nastaveni=textutils.unserialize(cnt)
term.setBackgroundColor(colors.white)
term.setTextColor(colors.black)
term.clear ()
term.setBackgroundColor(nastaveni.barva)
term.setCursorPos(1,1)
print "																							"
term.setBackgroundColor(colors.lightBlue)
term.setCursorPos(5,4)
print "- Run "
term.setCursorPos(5,6)
print "- Get "
term.setCursorPos(5,6)
print "- Put "
term.setCursorPos(5,7)
print "- End "
term.setBackgroundColor(colors.white)
while true do
local event, button, x, y = os.pullEventRaw()
if event == "mouse_click" then
if x <= 5 and x >= 10 and y == 4 and button == 1 then
spustit ()
elseif x <= 5 and x >= 10 and y == 6 and button == 1 then
ulozit ()
end
end
end
end
function spustit ()
print "vlozte kod"
kod1 = io.read ()
shell.run ("pastebin run",kod1)
end
function ulozit ()
print "vlozte kod"
kod1 = io.read ()
print "vlozte umisteni"
kod2 = io.read ()
shell.run ("pastebin get",kod1,kod2)
prohlizec ()
end
function nahrat ()
print "vlozte umisteni"
kod1 = io.read ()
shell.run ("pastebin put",kod1)
pokr = io.read ()
if pokr == "" then
pmenu ()
else
plocha ()
end
end
pmenu ()
Edited on 18 October 2014 - 06:07 PM
ElvishJerricco #2
Posted 18 October 2014 - 06:44 PM
Your title is horribly non-descriptive, your code isn't tabbed, and your post provides no information as to what the issue is. No one's going to help you if you don't give us anything to go on.

EDIT: Although I will point out, this is in your code, and will always evaluate to false

x <= 5 and x >= 10
Edited on 18 October 2014 - 04:52 PM
RadimBur #3
Posted 18 October 2014 - 08:06 PM
When I click on "run" does not do anything, so I ask what's wrong, because I could not find the problem.
Edited on 18 October 2014 - 06:06 PM
KingofGamesYami #4
Posted 18 October 2014 - 08:41 PM
Your problem, as Elvish stated, is this line:

if x <= 5 and x >= 10 and y == 4 and button == 1 then
Basically, you are saying "if x is less or equal to 5, and x is greater or equal to 10, and y is 4 and button is 1 then"
x cant be less than 5 and greater than 10 at the same time. I believe you meant:

if x >= 5 and x <= 10 and y == 4 and button == 1 then
Edited on 18 October 2014 - 06:41 PM
RadimBur #5
Posted 19 October 2014 - 06:55 PM
yes, thanks