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

Help!

Started by PlotTwistGamer, 09 August 2017 - 10:35 PM
PlotTwistGamer #1
Posted 10 August 2017 - 12:35 AM
I need help making clickable buttons. (Not through a monitor). I'm trying to make an operating system and I'm stuck with the basic "Type a command" types.
Bomb Bloke #2
Posted 10 August 2017 - 12:46 AM
http://www.computercraft.info/forums2/index.php?/topic/14784-touchpoint-api/
PlotTwistGamer #3
Posted 10 August 2017 - 01:43 AM
I don't think you read it right, I want buttons that have NOTHING TO DO with monitors. I want it IN COMPUTER. :3 Thanks
Bomb Bloke #4
Posted 10 August 2017 - 02:53 AM
I read correctly.
Saldor010 #5
Posted 10 August 2017 - 02:55 AM
I don't think you read it right, I want buttons that have NOTHING TO DO with monitors. I want it IN COMPUTER. :3 Thanks

I don't mean to sound rude, but if you don't know how to make something as simple as a clickable button, you probably aren't ready to dive right in to an operating system. Maybe focus on smaller projects first to build up your skill, then maybe later you could do an OS. Again, I'm not trying to be mean or patronizing, but trying to make something as complex as an OS for your first project is only going to frustrate you in the long run.
Edited on 10 August 2017 - 12:55 AM
PlotTwistGamer #6
Posted 10 August 2017 - 03:48 AM
I don't think you read it right, I want buttons that have NOTHING TO DO with monitors. I want it IN COMPUTER. :3 Thanks

I don't mean to sound rude, but if you don't know how to make something as simple as a clickable button, you probably aren't ready to dive right in to an operating system. Maybe focus on smaller projects first to build up your skill, then maybe later you could do an OS. Again, I'm not trying to be mean or patronizing, but trying to make something as complex as an OS for your first project is only going to frustrate you in the long run.

Hey, I asked for help. Not judgment.

EDIT: And I'm pretty good at making the "Type to comply" OS's. I just need help with a few things. And the best way to learn things is to do them. :3

SECOND EDIT: When did I say this was my first project? This is my 89 billionth project…

THE FRIGGIN THIRD EDIT: If you could help me on the matter that would be so FAHHN. (Also, the point of feeling success is working your way up from frustration to the feeling of success <3)
Edited on 10 August 2017 - 01:57 AM
Dave-ee Jones #7
Posted 10 August 2017 - 07:32 AM
I think, while he is being quite rude, he is correct. Best way to learn is to do it, but you still have to understand what you're doing.

Okay so button clicking is interesting. When you click on a button the program doesn't know there's a button there, it just sees you've clicked inside a range. For example look at the image below. The image on the left is how you see the program. If you click on one of those buttons all the program does is see that you've clicked within a certain range (the range being the range of the box, refer to the image on the right).


So here's a quick button script (draws a blue button with x, y, w, h as arguments):

function drawButton(x,y,w,h)
  term.setBackgroundColor(colors.blue)
  term.setCursorPos(x,y)
  for i=1,h do
	for i=1,w do
	  write(" ")
	end
	term.setCursorPos(x,y+i)
  end
end

Then a quick button-clicked-detection script might be:

while true do
  local event, button, X, Y = os.pullEvent()
  if event == "mouse_click" then
	if button == 1 then -- 1 means left-click on mouse
	  if X >= button1_x and X <= (button1_x + button1_w - 1) and Y >= button1_y and Y <= (button1_y + button1_h - 1) then
		 -- You clicked button 1!
	  ...

Why is there this huge line with "if X blah blah blah"? Well, that's saying "If you clicked within this X area (might start at 2 and end at 10, making it a button of 8 pixels in length) and you clicked within this Y area (might start at 10 and end at 13, making it a button with a height of 3) then you've clicked the button!

As you can see it's not really detecting a button click at all, it's just detecting that you've clicked in the same area as where the button was drawn. Pretty simple :)/>
[img]blob:http://imgur.com/f9ad0d8b-333f-48a7-82c3-378685c1c054[/img]
[img]blob:http://imgur.com/f9ad0d8b-333f-48a7-82c3-378685c1c054[/img]
Edited on 10 August 2017 - 05:33 AM
Lupus590 #8
Posted 10 August 2017 - 01:51 PM
I don't think you read it right, I want buttons that have NOTHING TO DO with monitors. I want it IN COMPUTER. :3 Thanks

from the touchpoint thread
you can also not specify a side, and the touchpoint instance will use the current terminal and watch for mouse_click events (ComputerCraft 1.6+ only)
PlotTwistGamer #9
Posted 03 September 2017 - 05:16 PM
I think, while he is being quite rude, he is correct. Best way to learn is to do it, but you still have to understand what you're doing.

Okay so button clicking is interesting. When you click on a button the program doesn't know there's a button there, it just sees you've clicked inside a range. For example look at the image below. The image on the left is how you see the program. If you click on one of those buttons all the program does is see that you've clicked within a certain range (the range being the range of the box, refer to the image on the right).


So here's a quick button script (draws a blue button with x, y, w, h as arguments):

function drawButton(x,y,w,h)
  term.setBackgroundColor(colors.blue)
  term.setCursorPos(x,y)
  for i=1,h do
	for i=1,w do
	  write(" ")
	end
	term.setCursorPos(x,y+i)
  end
end

Then a quick button-clicked-detection script might be:

while true do
  local event, button, X, Y = os.pullEvent()
  if event == "mouse_click" then
	if button == 1 then -- 1 means left-click on mouse
	  if X >= button1_x and X <= (button1_x + button1_w - 1) and Y >= button1_y and Y <= (button1_y + button1_h - 1) then
		 -- You clicked button 1!
	  ...

Why is there this huge line with "if X blah blah blah"? Well, that's saying "If you clicked within this X area (might start at 2 and end at 10, making it a button of 8 pixels in length) and you clicked within this Y area (might start at 10 and end at 13, making it a button with a height of 3) then you've clicked the button!

As you can see it's not really detecting a button click at all, it's just detecting that you've clicked in the same area as where the button was drawn. Pretty simple :)/>
[img]blob:http://imgur.com/f9ad0d8b-333f-48a7-82c3-378685c1c054[/img]
[img]blob:http://imgur.com/f9ad0d8b-333f-48a7-82c3-378685c1c054[/img]
Thank you so much! Sorry, I was in spokane and wasn't able to reply :3
PlotTwistGamer #10
Posted 23 October 2018 - 03:43 AM
I have come up with an issue, the system pops up an error code with "window:233: bad argument: double expected, got nil

The reason I wasn't able to test this code out until now is because my computer broke and now I have to use a crappy little laptop. I'm sorry I've required so much help. I've gotten better at shells and such but I really want to learn how to program a simple button and have it do things lol
EveryOS #11
Posted 23 October 2018 - 01:14 PM
THE FRIGGIN THIRD EDIT: If you could help me on the matter that would be so FAHHN. (Also, the point of feeling success is working your way up from frustration to the feeling of success <3)
I once wrote a lua OS (NyanOS). I got frustrated many times and when I released it I did not feel success…

I have come up with an issue, the system pops up an error code with "window:233: bad argument: double expected, got nil
It means you forgot a parameter when running the function
Bomb Bloke #12
Posted 23 October 2018 - 01:55 PM
I have come up with an issue, the system pops up an error code with "window:233: bad argument: double expected, got nil

The error is occurring within the window API, which acts as a layer of sorts in between your code and the terminal thanks to multishell. Odds are you're calling term.setCursorPos() incorrectly: you could probably use trace to narrow it down.