Jump to content




Clickable buttons in CC


  • You cannot reply to this topic
34 replies to this topic

#21 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 21 March 2013 - 05:46 AM

> not unreadable to me at least
> not error prone
> more efficient than looping through a table every time you click v_v
> my method is more dynamic

#22 thegreatstudio

  • Banned
  • 164 posts
  • LocationI am on your computer

Posted 21 March 2013 - 03:52 PM

Yeah hey. My os is now gui! Thanks for helping me theOriginalbit and engineer.

#23 Ristyo

  • Members
  • 31 posts
  • LocationIn my computer house located in a random village, programming.

Posted 22 March 2013 - 03:09 AM

im still confused how to make the buttons show up though

#24 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 22 March 2013 - 04:01 AM

View PostRistyo, on 22 March 2013 - 03:09 AM, said:

im still confused how to make the buttons show up though
you have to make them yourself
term.setCursorPos(2,2)
term.write("I'm a button!")

EDIT: or do what the original bit said

#25 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 22 March 2013 - 04:09 AM

View PostRistyo, on 22 March 2013 - 03:09 AM, said:

im still confused how to make the buttons show up though
Since the tutorial gets you to put x, y and text into a table
term.setBackgroundColor(colors.blue)
term.setTextColor(colors.white)
for i = 1, #buttons_table do
  local button = buttons_table[i]
  for y = 1, button[4] do
	for x = 1, button[3] do
	  term.setCursorPos( button[1] + x, button[2] + y )
	  write(' ')
	end
  end
  term.setCursorPos( button[1], button[2] )
  write( button[5] )
end
the above code would print them all out.

#26 ScruffyRules

  • Members
  • 98 posts

Posted 29 March 2013 - 08:24 PM

View PostEngineer, on 11 March 2013 - 10:18 AM, said:

local evt, button, x, y = os.pullEvent("mouse_click")
if x >= [your Xmin] and x <= [your xMax] and y >= [your yMin] and y <= [your yMax] then
-- your code
end

If you find any spelling errors or if you have a question post it below!
Also feedback is appreciated.



#27 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 30 March 2013 - 12:39 AM

View PostScruffyRules, on 29 March 2013 - 08:24 PM, said:

View PostEngineer, on 11 March 2013 - 10:18 AM, said:

local evt, button, x, y = os.pullEvent("mouse_click")
if x >= [your Xmin] and x <= [your xMax] and y >= [your yMin] and y <= [your yMax] then
-- your code
end

If you find any spelling errors or if you have a question post it below!
Also feedback is appreciated.

Thanks, edited out :)

#28 CtrlAltElite

  • Members
  • 10 posts

Posted 27 May 2013 - 06:32 PM

Multiple buttons
Let's go and process your values. I like them to put them in a table so you have later an easier way of determiningwich which button is clicked.

#29 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 28 May 2013 - 01:32 PM

View PostCtrlAltElite, on 27 May 2013 - 06:32 PM, said:

Multiple buttons
Let's go and process your values. I like them to put them in a table so you have later an easier way of determiningwich which button is clicked.
Thank you, edited it out!

#30 EpicPigChops

  • Members
  • 3 posts

Posted 01 June 2013 - 06:52 PM

How would you output the buttons to a monitor?

#31 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 01 June 2013 - 07:32 PM

You would use os.pullEvent('monitor_touch') instead of os.pullEvent('mouse_click')
And for your information, this tutorial is about making a button and not about displaying a button.

#32 Nytohan

  • New Members
  • 2 posts

Posted 03 June 2013 - 05:41 AM

I wish I had come here and read through the forums sooner, but I muddled through and came up with a reasonable method of getting clickable buttons on my advanced monitors.

I actually wrote a set of mini-operating systems that work together for the purpose of replacing the wireless redstone mod that will be leaving FTB if redpower doesn't get updated, and so far it's working splendidly!


Now, right off the bat I do not claim to be a world-class programmer. What I do claim to be is someone who can set a goal and make it happen, albeit sloppily, so if my code offends you, please keep the criticism constructive!

First off. this is a small screen sample of the final product:
http://dev.extrabit....l%20Display.png

It does adjust automatically, and on the fly, so you can place more screens and everything remains clickable without rebooting.

This is the configuration file for adding more buttons:
http://dev.extrabit....tons.config.png

You don't have to hard-code any coordinates, it will generate the button and keep track of its position for you.
The syntax here is Label: server event|state

The label is what you see on the screen, the server optional but it's where you want to send the command to with the channel number that server listens on in a separate config, and with an optional 't' before the servers name if the button is a toggle (can be turned on or off)

The event is the command name to send to that server, for the purposes of differentiation (one server can handle multiple clients which themselves deal directly with machines) and the state is the default starting state of the button.

True and false are pretty obvious, pulse means when the command reaches its client, the redstone pulses on for 1 second, then off (I use it to play music.)
and ~true and ~false are used when you want to have the button show the opposite of the redstone state.

For example, my witch spawner is off by default, but that means the restone is ON to prevent them from spawning. I want the computer to show that they are not spawning with the button being red(off) so I use ~false so that the display will show false but the redstone will be set to true.

For anyone who wants to peek at the code, it's available here:

http://dev.extrabit....nOS/buttons.lua

With the draw code being in my gui file.

If anyone has some ideas as to how I could improve this code, I'd welcome it, and if you would like to try the OS out, PM me and I will gladly share install instructions.

#33 Nytohan

  • New Members
  • 2 posts

Posted 03 June 2013 - 02:38 PM

View PostPixelToast, on 21 March 2013 - 05:46 AM, said:

> not unreadable to me at least
> not error prone
> more efficient than looping through a table every time you click v_v
> my method is more dynamic

I'm a tad confused, if you're using custom statements for your buttons, you still need a loop somewhere to determine which button was clicked, don't you?
Are you placing each one as a possible if...then inside your main program loop?
Also, how is it "more dynamic", what's the advantage of your buttons over the tutorials buttons?
Would you be willing to share a code sample?

#34 cory1234567

  • Members
  • 25 posts

Posted 07 June 2013 - 08:24 AM

a video of this tutorial would be very helpful

#35 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 11 June 2013 - 05:50 AM

View Postcory1234567, on 07 June 2013 - 08:24 AM, said:

a video of this tutorial would be very helpful
I am going to leave that to others, since Im not that good in pronouncing English..





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users