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

Split from Openperipheral topic.

Started by Gent202, 08 January 2014 - 08:41 PM
Gent202 #1
Posted 08 January 2014 - 09:41 PM
Hello everyone. I recently started working on a program to monitor my Applied Energistics system. I managed to get the display functioning correctly. One issue that I was attempting to fix was the auto-update. The issue I am trying to fix is that whenever a value on the display changes, instead of getting rid of the old value the two displays merge, making a very messy jumble fo words. I am completely new to programming, and have absolutely no idea how to fix this. If anyone would be able to help me get back on track, that would be great.

Here is my code:

bridge = peripheral.wrap("bottom")
sys = peripheral.wrap("back")

--Startup Script

bridge.clear()

--Applied Energistics Module
  while true do
    methods = sys.callRemote("appeng_me_tilecontroller_0","listMethods")
    bytfree = sys.callRemote("appeng_me_tilecontroller_0","getFreeBytes")
    bytmax = sys.callRemote("appeng_me_tilecontroller_0","getTotalBytes")
    outline = bridge.addBox(0,196,84,58,0x1b2344,1)
    outline.setZIndex(1)
    modspace = bridge.addBox(0,200,80,50,0x895ca8,1)
    modspace.setZIndex(2)
    textbyte1 = bridge.addText(modspace.getX() + 2,modspace.getY() + 2,(bytfree.." bytes free"),0xFFFFFF)
    textbyte1.setZIndex(3)
    bytfree2 = tonumber(bytfree)
	  if bytfree2 < 1
	    then textbyte1.setColor(0xFF0000)
	    else textbyte1.setColor(0x28FF00)
	  end
    textbyte2 = bridge.addText(modspace.getX() + 2,textbyte1.getY() + 10,("out of "..bytmax.."."),0xFFFFFF)
    textbyte2.setZIndex(4)
    freespace = sys.callRemote("appeng_me_tilecontroller_0","getRemainingItemCount")
    spaceav = bridge.addText(modspace.getX() + 2,textbyte2.getY() + 10,("Storage space"),0xFFFFFF)
    spaceav.setZIndex(5)
    freespace2 = tonumber(freespace)
    spaceav2 = bridge.addText(modspace.getX() + 2, spaceav.getY() + 10,("is ?"),0xFFFFFF)
	   if freespace2 < 100
		 then
		   spaceav2.setText("is tight.")
		   spaceav2.setColor(0xFFBF00)
		 else
		   spaceav2.setText("is available.")
		   spaceav2.setColor(0x28FF00) 
	   end
    spaceav2.setZIndex(6)
    modname = bridge.addText(modspace.getX() + 2, spaceav2.getY() + 10,("Applied Energistics"),0x00EEFF)
    modname.setZIndex(7)
    modname.setScale(0.7)
  end

Also, a side question: is there any way to adjust the position of the display to match the users screen resolution?
Thanks again! :D/>
Lyqyd #2
Posted 09 January 2014 - 12:19 AM
I've split this from the openperipheral topic.
CometWolf #3
Posted 09 January 2014 - 02:23 AM
To update the text, you need to use setText on the text element you wish to change, instead of creating a new text element. As for resolution, there is not. The way i handle it is just a simple $$command to change it
theoriginalbit #4
Posted 09 January 2014 - 02:48 AM
As for resolution, there is not. The way i handle it is just a simple $$command to change it
And now with the development betas you can render out to certain players, and know when they join the game and obviously when they send a command. All this allows for you to make a command system where users can tell you their resolution and the program can individually control each players. requires build 80 or higher (if i remember correctly)

EDIT: I'm still (kinda) looking into a way to get resolution sizes accurately and reliably for use when modifying individual users screens, but its proving to be difficult.
Edited on 09 January 2014 - 01:50 AM
Gent202 #5
Posted 09 January 2014 - 07:05 PM
To update the text, you need to use setText on the text element you wish to change, instead of creating a new text element. As for resolution, there is not. The way i handle it is just a simple $$command to change it
Ok, I have updated my code to use setText, but the old text still stays where it is when it changes.
Here is the modified code:

bridge = peripheral.wrap("bottom")
sys = peripheral.wrap("back")
--Startup Script
bridge.clear()
--Applied Energistics Module
  while true do
    methods = sys.callRemote("appeng_me_tilecontroller_0","listMethods")
    bytfree = sys.callRemote("appeng_me_tilecontroller_0","getFreeBytes")
    bytmax = sys.callRemote("appeng_me_tilecontroller_0","getTotalBytes")
    outline = bridge.addBox(0,196,84,58,0x1b2344,1)
    outline.setZIndex(1)
    modspace = bridge.addBox(0,200,80,50,0x895ca8,1)
    modspace.setZIndex(2)
    textbyte1 = bridge.addText(modspace.getX() + 2,modspace.getY() + 2,(""),0xFFFFFF)
    textbyte1.setZIndex(3)
    bytfree2 = tonumber(bytfree)
	  if bytfree2 < 1
	    then textbyte1.setColor(0xFF0000)
	    else textbyte1.setColor(0x28FF00)
	  end
    textbyte2 = bridge.addText(modspace.getX() + 2,textbyte1.getY() + 10,(""),0xFFFFFF)
    textbyte2.setZIndex(4)
    textbyte1.setText(bytfree.." bytes free")
    textbyte2.setText("out of "..bytmax..".")
    freespace = sys.callRemote("appeng_me_tilecontroller_0","getRemainingItemCount")
    spaceav = bridge.addText(modspace.getX() + 2,textbyte2.getY() + 10,("Storage space"),0xFFFFFF)
    spaceav.setZIndex(5)
    freespace2 = tonumber(freespace)
    spaceav2 = bridge.addText(modspace.getX() + 2, spaceav.getY() + 10,(""),0xFFFFFF)
	   if freespace2 < 100
		 then
		   spaceav2.setText("is tight.")
		   spaceav2.setColor(0xFFBF00)
		 else
		   spaceav2.setText("is available.")
		   spaceav2.setColor(0x28FF00) 
	   end
    spaceav2.setZIndex(6)
    modname = bridge.addText(modspace.getX() + 2, spaceav2.getY() + 10,("Applied Energistics"),0x00EEFF)
    modname.setZIndex(7)
    modname.setScale(0.7)
  end
CometWolf #6
Posted 10 January 2014 - 12:12 AM
It's because your addText is in a while true do loop. You can either clear the glasses at the start of it, or just add the text elements outside of it and use setText inside it.
theoriginalbit #7
Posted 10 January 2014 - 12:17 AM
but I definitely recommend adding the text outside the loop and then using the setter to change it. clearing the glasses all the time can cause flicker, and causes a lot more transmission between servers and clients.
Gent202 #8
Posted 10 January 2014 - 04:17 PM
I finally got it working by putting the addTexts outside of the loop! :D/> I also cleaned up the code a lot.
Here is the working copy: http://pastebin.com/MVUDBBre
I am really looking forward to adding resolution detection, but commands will work for now!
Thanks everyone!