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

What am I making wrong?

Started by rdmGAMER, 26 June 2016 - 01:07 PM
rdmGAMER #1
Posted 26 June 2016 - 03:07 PM
I'm trying to make an OS, but the events that I code aren't working. Why? Please help.

Here is one part of the event codes :

while true do
local event, X, Y = os.pullEvent("mouse_click")
if X==4 and Y==6 then
login()
break
elseif X==4 and Y==8 then
register()
break
end
end
Dog #2
Posted 26 June 2016 - 03:12 PM
You're forgetting to parse for the mouse button pressed…

local event, button, X, Y = os.pullEvent("mouse_click")
rdmGAMER #3
Posted 26 June 2016 - 03:13 PM
EDIT : I tried it out and it isn't working :unsure:/>
Edited on 26 June 2016 - 01:16 PM
Dog #4
Posted 26 June 2016 - 03:37 PM
Please post the code you tried.
rdmGAMER #5
Posted 26 June 2016 - 03:38 PM
Here it is :

Spoiler
os.loadAPI(".sys/API/kernal")
local login = kernal.getTable(".opt/logon/.uacc")
local usr1 = string.sub(login[1], string.find(login[1], ":")+2)
local pass1 = string.sub(login[2], string.find(login[2], ":")+2)
local usr2 = string.sub(login[3], string.find(login[3], ":")+2)
local pass2 = string.sub(login[4], string.find(login[4], ":")+2)
local usr3 = string.sub(login[5], string.find(login[5], ":")+2)
local pass3 = string.sub(login[6], string.find(login[6], ":")+2)
function login()
term.setBackgroundColor(8)
term.clear()
term.setTextColor(1)
paintutils.drawLine(1,1,51,1,colors.blue)
paintutils.drawLine(1,19,51,19,colors.blue)
term.setCursorPos(1,19)
write("© 2016 erik0004")
term.setCursorPos(1,1)
print("OS'16 Login")
term.setBackgroundColor(8)
term.setCursorPos(5,9)
print("Password : ")
term.setCursorPos(5,7)
write("Username : ")
input = read()
if input == usr1 or input == usr2 or input == usr3 then
  term.setCursorPos(5,9)
  write("Password : ")
  input = read("*")
  if input == pass1 or input == pass2 or input == pass3 then
  term.setCursorPos(7,12)
  textutils.slowPrint("Welcome, please wait.")
  sleep(0.5)
  term.setCursorPos(5,12)
  print([[|]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[/]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[-]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[\]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[|]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[/]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[-]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[\]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[|]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[/]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[-]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[\]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[|]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[/]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[-]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[\]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[|]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[/]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[-]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[\]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[|]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[/]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[-]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[\]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[|]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[/]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[-]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[\]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[|]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[/]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[-]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[\]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[|]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[/]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[-]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[\]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[|]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[/]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[-]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[\]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[|]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[/]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[-]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[\]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[|]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[/]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[-]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[\]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[|]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[/]])
  sleep(0.1)
  term.setCursorPos(5,12)
  print([[-]])
  sleep(0.2)
  term.setCursorPos(5,12)
  print([[ ]])
  sleep(0.5)
  shell.run(".sys/GUI/desktop")
  else
  term.setCursorPos(5,12)
  print("Incorrect Password!")
  sleep(3)
  shell.run(".sys/logon/usr_login")
  end
else
term.setCursorPos(5,12)
print("Incorrect Username!")
sleep(3)
shell.run(".sys/logon/usr_login")
end
end
function register()
term.setBackgroundColor(8)
term.clear()
term.setTextColor(1)
paintutils.drawLine(1,1,51,1,colors.blue)
paintutils.drawLine(1,19,51,19,colors.blue)
term.setCursorPos(1,19)
write("© 2016 erik0004")
term.setCursorPos(1,1)
print("OS'16 Register")
end
function drawLogin()
term.setBackgroundColor(8)
term.clear()
term.setTextColor(1)
paintutils.drawLine(1,1,51,1,colors.blue)
paintutils.drawLine(1,19,51,19,colors.blue)
term.setCursorPos(1,19)
write("© 2016 erik0004")
term.setCursorPos(1,1)
print("OS'16 Login")
term.setBackgroundColor(8)
  term.setCursorPos(6,6)
print("Login")
term.setCursorPos(6,8)
print("Register")
term.setTextColor(colors.red)
term.setCursorPos(4,6)
print("X")
term.setCursorPos(4,8)
print("X")
end
drawLogin()
while true do
local event, X, Y, button = os.pullEvent("mouse_click")
if X == 4 and Y == 6 and button == 1 then
login()
break
end
  if X == 4 and Y == 8 and button == 1 then
  register()
  break
  end
end

(Its long so I put it in a spoiler)
Edited on 26 June 2016 - 01:40 PM
Dog #6
Posted 26 June 2016 - 03:45 PM
The reason it's not working is because you're capturing the button in X, X is being captured in Y, and Y is being captured in button. The order in which the information is returned doesn't change, you must order your variables correctly.

This is your line:

local event, X, Y, button = os.pullEvent("mouse_click")

and this is what I suggested:

local event, button, X, Y = os.pullEvent("mouse_click")

Do you see the difference?
rdmGAMER #7
Posted 26 June 2016 - 03:53 PM
Okay… I already programmed 2 OS' and I never had that problem. I also had

local event , X, Y, button = os.pullEvent("mouse_click")
in exactly this order. I don't understand why it is now so

But thank you