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

Code for clicks

Started by CptBlank, 22 April 2014 - 12:34 PM
CptBlank #1
Posted 22 April 2014 - 02:34 PM
Okay i want to when i click Blank_Explorer it opens a file called BlankEXP
when i click shutdown i want it to shutdown and when i click reboot for it to reboot.

To make it just edit the code from the spoiler and give me your code in my original code

About the section i am basically asking pros for code

Code:

term.setBackgroundColor (colors.white)
term.setTextColor (colors.black)
term.clear()
term.setCursorPos (1,1)
image = paintutils.loadImage ("/LocalDrive/BlankOS/System/Images/Dock")
paintutils.drawImage (image, 1, 1)
term.setCursorPos (1,1)
print ("BlankOS")
term.setCursorPos (12,1)
print ("Blank_Explorer")
term.setCursorPos (27,1)
print ("Shutdown")
term.setCursorPos (36,1)
print ("Reboot")
term.setCursorPos (44,1)
local time = os.time()
time = textutils.formatTime (time, false)
print (""..time)
term.setCursorPos (1,21)   ---thing that hides the cursor,makes it under the whole screen thats white



EDIT2:I tried doing the mouse events tutorial and used this command

the tutorial is here btw http://babycodderblog.wordpress.com/2013/04/12/computercraft-using-computer-clicks-and-adv-monitor-touches-as-inputs/

event, button, x, y = os.pullEvent ("mouse_click)
if button == 1 and x == 27 and y == 1 then
sleep (1)
os.shutdown()
end

Nothing happens when i use that code even if i wait 100 seconds

however if i replace x == 27 with x == 1 then it works properly by clicking the corner
Edited on 22 April 2014 - 01:33 PM
viluon #2
Posted 22 April 2014 - 02:44 PM
I bet that setting the button only to one pixel isn't really what u want… try using e.g. if x>=10 and x<=12 and… to set the actual button size. Also, in your code there's missing " in os.pullEvent

To hide cursor, set term.setCursorBlink(false)

Edit: in your case, do the comparison for button size with y:
 if y>=27 and y<=35 and x=1 then os.shutdown() end

Advice: Don't start off with programming by trying to create an OS. First learn Lua http://lua.org/pil/contents.html and adapt it to cc http://computercraft.info/wiki then continue to the next level. You would be sad after releasing your OS that nobody likes it and they call it useless. Look through the forums, look at what others did and learn from their code.
Edited on 22 April 2014 - 01:01 PM
CptBlank #3
Posted 22 April 2014 - 03:27 PM
xD too dumb for the events
just dump the code for shutting down and rebooting in my code above
Edited on 22 April 2014 - 01:30 PM
CometWolf #4
Posted 22 April 2014 - 03:31 PM
If you set cursor blink to false it's not visible no matter where it is. It's false by default when you run your programs, so you usually don't need to worry about it.