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

Selector Touchscreen

Started by R167, 20 February 2013 - 06:19 PM
R167 #1
Posted 20 February 2013 - 07:19 PM
What it is
I have recently written a script for advanced computers and advanced monitors. It so far does nothing except for allow you to select the option that you want.

What it does
Currently, nothing. It has huge potential and the possibility to be expanded to larger monitors and control stuff, but for now, it just makes pretty colored text for the words on and off.

Goal
I hope to make this into its own fully standalone setup (not that it isn't already) that can control tier 5 spawners from the soul shards mod. I have not yet done so, but will post when it is done. Tip: If Redpower is installed, you can use cover strips to cover up the gold border around the monitor.

Setup
Requires an advanced computer witha monitor to the right (configurable) with at least the size of 4 wide by 3 high advanced monitors. Right click to change the state of things.

Script
Here is the script, you can directly download from pastebin.com if you have http access turned on in the config by pasting in
pastebin get 6jjXTe4m "name for script"
into the advanced computer.

Code on:
New code: http://pastebin.com/6jjXTe4m
Old code: http://pastebin.com/sdRpkiT1

Screenshots:
Spoiler










Old Code:
SpoilerPlease note, code pasted here is not necessarily up to date at all times. Please check pastebin.com for the most recent version of the code.


--Requires advanced monitors and computers!!!
function toggle(n)
  if not n then
	return
  end
  local state=lightState[n]
  if state then
	state = false
  else
	state = true
  end
  lightState[n] = state
  return state
end
function sayState(n)
  if not n then
	return
  end
  x = buttonX[n]-1
  y = buttonY[n]
  term.setCursorPos(x,y)
  if lightState[n] then
	term.setTextColor(colors.lime)
	write("on ")
	term.setTextColor(colors.white)
  else
	term.setTextColor(colors.red)
	write("off")
	term.setTextColor(colors.white)
  end
end
function getButton(xPos,yPos)
  for i=1,12 do
	bxPos=buttonX[i]
	byPos=buttonY[i]
	xMax=bxPos+2
	xMin=bxPos-2
	yMax=byPos+1
	yMin=byPos-1
	if xPos >= xMin and xPos <= xMax and yPos >= yMin and yPos <= yMax then
	  return i
	end
  end
end
function mPrint(w)
  write(w)
  x,y=term.getCursorPos()
  term.setCursorPos(1,y+1)
end
function allTheSame()
  local state = lightState[1]
  for i=2,10 do
	if state==lightState[i] then
	else return false
	end
  end
  return true
end
function stateWriter()
  mPrint("  _____	 _____	 _____	 _____")
  write("  ")
  for i=1,4 do
	write("|")
	term.setTextColor(colors.red)
	write("off")
	term.setTextColor(colors.white)
	if i<4 then
	  write("|	 ")
	else
	  mPrint("|")
	end
  end
  mPrint("  ~~~~~	 ~~~~~	 ~~~~~	 ~~~~~")
end
function startText()
  term.setCursorPos(1,1)
  mPrint("_______________________________________")
  mPrint(" Welcome to spawn select! Control mob")
  mPrint(" spawn choice by right click on screen")
  mPrint(" ")
  mPrint("  Skele	 Wither	Ender	 Zombie")
  stateWriter()
  mPrint(" ")
  mPrint("  Creep	 Witch	 Pigman	Cow")
  stateWriter()
  mPrint(" ")
  mPrint("  Blaze	 Slime	 Toggle	Master")
  stateWriter()
  mPrint("_______________________________________")
end
function bundleState()

end
display = peripheral.wrap("right")
term.redirect(display)
term.clear()
term.setCursorPos(1,1)
buttonX = {
5,15,25,35,
5,15,25,35,
5,15,25,35
}
buttonY = {
7,7,7,7,
12,12,12,12,
17,17,17,17
}
lightState = {false,false,false,false,false,false,false,false,false,false,false,false}
spawnerColor = {
colors.white, colors.orange, colors.magenta, colors.lightBlue,
colors.yellow, colors.lime, colors.pink, colors.gray,
colors.lightGray, colors.cyan, colors.purple, colors.blue
}
local resume=true
startText()
for i=1,10 do
  sayState(i)
end
term.setCursorPos(buttonX[12]-1,buttonY[12])
term.setTextColor(colors.red)
write("off")
term.setTextColor(colors.white)
term.setCursorPos(buttonX[11]-1,buttonY[11])
term.setTextColor(colors.cyan)
write("TGL")
term.setTextColor(colors.white)
while resume == true do
  local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  local button = getButton(xPos,yPos)
  if button==11 then
	for i=1,10 do
	  toggle(i)
	end
  elseif button==12 then
	toggle(12)
	for i=1,10 do
	  lightState[i]=lightState[12]
	end
	sayState(12)
	allSame=true
  else
	term.setCursorPos(buttonX[12]-1,buttonY[12])
	term.setTextColor(colors.lightGray)
	write("---")
	term.setTextColor(colors.white)
	toggle(button)
  end
  for i=1,10 do
	sayState(i)
  end
  if allTheSame() then
	lightState[12]=lightState[1]
	sayState(12)
  else
	term.setCursorPos(buttonX[12]-1,buttonY[12])
	term.setTextColor(colors.lightGray)
	write("---")
	term.setTextColor(colors.white)
  end
end

--[==[Tables are used to quite an extent throughout this program.
The order of said tables is important as these must remain consistent in order for the script to execute.]==]

If you spot any errors, please point them out. :)/>
AnDwHaT5 #2
Posted 21 February 2013 - 05:11 PM
Hmm im getting errors and im not good enough with functions to fix this issue.
Skullblade #3
Posted 21 February 2013 - 05:13 PM
Tell him the errors and when they occur
R167 #4
Posted 22 February 2013 - 05:25 PM
Hmm im getting errors and im not good enough with functions to fix this issue.

What errors? Haven't gotten any except for a while ago before I had updated it. That was pre posting it though. Thanks for the feed back. Please list at lead the line the error was found on. Also, a reinstall might fix it. Thank you again.
R167
remiX #5
Posted 23 February 2013 - 02:36 AM
Screenshots .. :}
AnDwHaT5 #6
Posted 23 February 2013 - 09:26 AM
I will when I get home
Cozzimoto #7
Posted 23 February 2013 - 09:35 AM
good stuff, sounds similar to what direwolf created on forgecraft. =P
AnDwHaT5 #8
Posted 23 February 2013 - 11:25 AM
one error i get is term:16: Invalid redirect object. Thats a different one then i got before…
marted #9
Posted 24 February 2013 - 05:40 AM
Errors?
TwelveEight #10
Posted 25 February 2013 - 07:50 PM
one error i get is term:16: Invalid redirect object. Thats a different one then i got before…

That will happen if you don't read either the script or what the OP told you to…. -.-
No biggie, just place a 4 wide x 3 tall adv. monitor setup next to your advanced computer.


function sayState(n)
  if not n then
    return
  end

If I'm not mistaken, this calls (for lack of the right word) the advanced monitor. Without it, you get an error on line 16/17.
R167 #11
Posted 12 March 2013 - 11:59 AM
Yes, 4 wide by 3 tall monitor is what this calls for. I also just made this program actually functional and with a purpose. It no has the bundled cable output!!! :)/> . Here is the link. http://pastebin.com/6jjXTe4m. It may or may not work. Just putting it up there for now.
Amokaci #12
Posted 12 April 2013 - 04:52 AM
Hello

i like the idea with that script

but i have a problem i used 1 advance computer and 12 advance monitor but i got a weired error can u help ?

i look at the code and all was fine

i typed: monitor right touch back

then this expand the spoiler:
Spoiler

i hope u can help me
Amokaci #13
Posted 12 April 2013 - 11:51 AM
fixed it sry
EntwinedBirch #14
Posted 01 May 2013 - 02:49 AM
I have a small problem. The display will appear on my monitor correctly, generally speaking, but at the bottom it tells me lua expected a number at line 213. Can you please help?
darkrising #15
Posted 01 May 2013 - 05:32 AM
This is cool! :P/>

By the way I have a very similar program called dark buttons
EntwinedBirch #16
Posted 01 May 2013 - 01:48 PM
Sorry about that. I figured out the my issue was that I used lightGrey with colors. Small error in one letter.
kauqilla #17
Posted 03 May 2013 - 02:27 PM
what blocks are those used to suspend the cabling?
theoriginalbit #18
Posted 03 May 2013 - 02:30 PM
what blocks are those used to suspend the cabling?
Its RedPower 2… It provides better cabling and the ability to have suspended cables…
The suspended ones have the identifier Jacketed in front of the cable name.
kauqilla #19
Posted 03 May 2013 - 02:35 PM
i meant the obsidian microblocks but its all good now
starwind #20
Posted 29 May 2013 - 05:03 AM
Hey ;)/>

Love your script, tho i have a question,

Is it possible to have this script send a singnal to a turtlee?


like i have a turtle shearing sheeps, would it be possible to turn them on and off from this script?
cory1234567 #21
Posted 07 June 2013 - 02:00 PM
could you add an option for just normal redstone cause redpower isnt updated for 1.5.2 it would really help alot
brendant123 #22
Posted 19 June 2013 - 09:20 PM
Is it possible to use this with rednet API network cables, because as everyone knows redpower isnt updated.
R167 #23
Posted 18 August 2013 - 01:05 PM
Hey ;)/>

Love your script, tho i have a question,

Is it possible to have this script send a singnal to a turtlee?


like i have a turtle shearing sheeps, would it be possible to turn them on and off from this script?

could you add an option for just normal redstone cause redpower isnt updated for 1.5.2 it would really help alot

Is it possible to use this with rednet API network cables, because as everyone knows redpower isnt updated.

I might be able to adapt the script to do all of this. I think that the way to go would be to add an "activate"/"turn_on" function. This may be able to do stuff like, Activate certain redstone on specific side for some stuff, rednet/network cables, as well as a semi complicated way with t-flipflops for entire vanilla purposes.

PS I believe that the bundled cables work with Minefactory Reloaded cables as of computer craft 1.5.3

PPS Will work on updating soon-ish
mb55177 #24
Posted 09 April 2014 - 08:00 PM
does this work with project red as so far according to my testing it does not
and also if it only works with redpower then redpower Is kinda dead
Edited on 09 April 2014 - 06:00 PM
apemanzilla #25
Posted 09 April 2014 - 08:51 PM
does this work with project red as so far according to my testing it does not
and also if it only works with redpower then redpower Is kinda dead
Woah there, necro

Anyways, in CC 1.58 it should work with MFR bundled cables. In CC 1.6, the other mods need to add support.
mb55177 #26
Posted 09 April 2014 - 09:06 PM
i'll check later when I get time what version of CC I'm using but it is the direwolf20 FTB launcher pack