Jump to content




Split from Openperipheral topic.


7 replies to this topic

#1 Gent202

  • Members
  • 3 posts

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

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 09 January 2014 - 12:19 AM

I've split this from the openperipheral topic.

#3 CometWolf

  • Members
  • 1,283 posts

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

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2014 - 02:48 AM

View PostCometWolf, on 09 January 2014 - 02:23 AM, said:

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 by theoriginalbit, 09 January 2014 - 02:50 AM.


#5 Gent202

  • Members
  • 3 posts

Posted 09 January 2014 - 07:05 PM

View PostCometWolf, on 09 January 2014 - 02:23 AM, said:

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


#6 CometWolf

  • Members
  • 1,283 posts

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.

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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.

#8 Gent202

  • Members
  • 3 posts

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users