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

direwolf20 aspect refill + Thaumic energistics

Started by IceCupe123, 27 April 2016 - 01:10 PM
IceCupe123 #1
Posted 27 April 2016 - 03:10 PM
I want that the direwolf20 aspect refill programm read the essentia from the ae network insted from the jars but its only show 1 aspect

http://prnt.sc/axhpnf

my code:
Spoiler


--rednet.open("left")
os.loadAPI("button")
local turtleID = 40
local essentia = {}
local jars = peripheral.getNames()
local m = peripheral.wrap("top")
local monCoord = {}
local currEssentia
local fillAmt = 0
local rowsActive = true
function sortEss(t)
   local keys = {}
   for k in pairs(t) do keys[#keys+1] = k end
   table.sort(keys)
  
   local i = 0
   return function()
	  i = i+1
	  if keys[i] then
		 return keys[i], t[keys[i]]
	  end
   end
end
function scanEssentia()
  for i,j in ipairs(jars) do
	 if peripheral.getType(j) == "EssentiaProvider" then
	   asp = peripheral.call(j, "getAspects")
	   countasp = peripheral.call(j, "getAmount", asp)
	   if countasp > 0 then
		  essentia[asp] = math.floor(countasp)
	   end
	   print(countasp)
	 print(asp..":"..countasp)
	 print(peripheral.getType(j))
	 end
  end
end
function printEssentia()
  m.setTextColor(colors.white)
  local x = 1
  local y = 1
  monCoord[x] = {}
--  for a = 1,17 do
  for i,j in sortEss(essentia) do
	 if j<=20 then m.setTextColor(colors.red) end
	 if j<40 and j>20 then m.setTextColor(colors.yellow) end
	 if j>=40 then m.setTextColor(colors.green) end
	
	 m.setCursorPos(x,y)
	 m.write(i)
	 m.setCursorPos(x+14,y)
	 m.write(tostring(j))
--	 print(j)
	 monCoord[x][y] = i
	 if y < 17 then
		y = y+1
	 else
		y = 1
		x = x+17
		monCoord[x] = {}  
	 end
  end
-- end
m.setTextColor(colors.white)
end
function getClick()
   local event,side,x,y = os.pullEvent()
   if event=="monitor_touch" then
	 if button.checkxy(x,y) then
		print("button")
	 else
		if rowsActive then
		  fillAmt = 0
		  print(x..":"..x-(x%17)+1)
		  print(monCoord[x-(x%17)+1][y])
		  currEssentia = monCoord[x-(x%17)+1][y]
		  if currEssentia ~= nil then
		  if essentia[currEssentia] < 64 then
			 fillTable2()
		  else
			 m.clear()
			 button.label(1,10, currEssentia.." is already full.  Please choose another.")
			 sleep(3)
			 refresh()
		  end
		  end
		end
	 end
   end
end
function refresh()
   button.flash("Refresh")
   m.clear()
   scanEssentia()
   printEssentia()
   print("Refreshed")
   button.screen()
end
function fillTable()
   rowsActive = true
   button.clearTable()
   button.setTable("Refresh", refresh, "", 15, 35, 19, 19)
   button.screen()
end
function addEss(num)
   fillAmt = fillAmt + num
   if fillAmt < 0 then fillAmt = 0 end
   if fillAmt > 64-essentia[currEssentia] then fillAmt = 64-essentia[currEssentia] end
   m.clear()
   fillTable2()
end
function fillEss()
   local essData = {}
   essData[1] = currEssentia
   essData[2] = fillAmt
   local sendData = ""
   sendData = textutils.serialize(essData)
   rednet.send(turtleID, sendData)
   m.clear()
   button.label(7, 10, "Waiting for aspects to finish cooking....")
   button.label(7, 12, "Don't forget to refresh the screen after")
   button.label(7, 13, "the golem is done moving the essentia.")
   rednet.receive()
   m.clear()
   fillTable()
   refresh()
end
function cancel()
   m.clear()
   fillTable()
   refresh()
end  
function fillTable2()
   rowsActive = false
   button.clearTable()
   m.clear()
   button.label(7, 1, "Essentia: "..currEssentia.." contains "..essentia[currEssentia])
   button.setTable("+1", addEss, 1, 8, 18, 6,6)
   button.setTable("+5", addEss, 5, 20, 30, 6, 6)
   button.setTable("+10", addEss, 10, 32, 42, 6, 6)
   button.setTable("-1", addEss, -1, 8, 18, 8, 8)
   button.setTable("-5", addEss, -5, 20, 30, 8, 8)
   button.setTable("-10", addEss, -10, 32, 42, 8 ,8)
   button.setTable("Refill Jar", addEss, 64-essentia[currEssentia], 8, 42, 10, 10)
   button.setTable("Execute Fill Request", fillEss, "", 8, 42, 16, 18)
   button.setTable("Cancel", cancel, "", 20, 30, 12, 14)
   button.label(7, 4, "Currently Adding "..fillAmt.." "..currEssentia.." essentia.")
   button.screen()
end
fillTable()
refresh()
while true do getClick() end
Bomb Bloke #2
Posted 28 April 2016 - 02:39 AM
This script seems to expect one aspect per "EssentiaProvider" peripheral. I wouldn't know, but I'd be surprised if an AE system has an component that counts as an "EssentiaProvider" in the first place… I'm sorta suspecting you've still got a jar of some sort hooked up somewhere, and it's getting the one aspect it does show from that?
Stekeblad #3
Posted 28 April 2016 - 11:35 AM
Thaumic Energistics adds a way to store Thaumcraft aspects in the ME system and has a provider block. From what I seen it works like jars close to the
infusion matrix. The infusion draws the essence it needs from the ME system through one provider.

I guess the problem is that you only get one essentia type is in scanEssentia()
The original code loops over all jars that have one type each, you have all types in one block. I think that when the program calls for getAspects it returns a table but the result is not handle as a table and only the first row shows up.
Bomb Bloke #4
Posted 28 April 2016 - 11:48 AM
I think that when the program calls for getAspects it returns a table but the result is not handle as a table and only the first row shows up.

Not exactly possible - if a table were returned, the script would likely crash - but it's true that getAspects may have multiple return values.

Try this in the Lua console:

print(peripheral.call(<"provider"BlockNameHere>, "getAspects"))

What's that give you?
IceCupe123 #5
Posted 28 April 2016 - 12:14 PM
i get a 1
Bomb Bloke #6
Posted 28 April 2016 - 01:33 PM
Then you aren't entering the name of your AE "provider block" thingy correctly. When you've fixed it, it'll output "Humanus" before that, at a minimum (assuming you haven't taken out all the aspects, or something).

Remember, if the block is directly next to your computer, then you need to enter the name of the side it's attached to (eg, "left", "right", "top"…). If the block is attached via a wired modem, then activating the modem to connect / disconnect it will instead give you the correct name to use.
IceCupe123 #7
Posted 28 April 2016 - 01:38 PM
ups now i get this

Bomb Bloke #8
Posted 28 April 2016 - 01:50 PM
Ah, now that we can maybe work with:

function scanEssentia()
	essentia = {}
	for i,j in ipairs(jars) do
		if peripheral.getType(j) == "EssentiaProvider" then
			asp = {peripheral.call(j, "getAspects")}          --# Take all results, stick them in a table.
			if #asp == 1 then  --# This may be needed for regular jars?
				countasp = peripheral.call(j, "getAmount", asp[1])
				if countasp > 0 then
					essentia[asp[1]] = math.floor(countasp)
				end
			else  --# As for your provider block thingy:
				for k = 0, #asp / 2 - 1 do
					essentia[asp[k*2+1]] = asp[k*2+2]
				end
			end
		end
	end
end
IceCupe123 #9
Posted 28 April 2016 - 01:57 PM
nice it work :D/> but its so squeezed how i get a bit distance betwen the left and right tabel

Edited on 28 April 2016 - 11:57 AM
Bomb Bloke #10
Posted 28 April 2016 - 02:02 PM
Mess with the numbers next to the "x+"s in the printEssentia() function.
IceCupe123 #11
Posted 28 April 2016 - 02:04 PM
thanks for ur help
andythornton #12
Posted 31 March 2017 - 02:31 AM
By chance, was this finalized code listed anywhere? Following the Direwolf20 Season 7 right now myself and did the same thing - stored Essentia in the Network rather than in jars. Would love to see the full thing on a screen though as mentioned in this thread. Just learning Computercraft code now too, so hate to try reinventing the wheel if this was already done. Heh.
Bomb Bloke #13
Posted 01 April 2017 - 10:42 AM
By chance, was this finalized code listed anywhere?

I don't believe so, but if you take the code IceCupe quoted within his first post, replace the scanEssentia() function with the one I provided lower down, and then adjust the numbers in the printEssentia() function to get the spacing you want, you should likewise be set to go.
andythornton #14
Posted 01 April 2017 - 12:41 PM
Awesome, will give this a try!

Thanks!
andythornton #15
Posted 01 April 2017 - 02:43 PM
Attempting to give it all a shot now and getting stuck on one part. I got the Screen set so that its showing correctly (had to reconfigure the Button program I found), but its not doing anything with regards to calling Aspects. I put the provider (which has a ListMethod available of getAspects) that is directly below the computer. When I try that string above into the LUA (print(peripheral.call(<"provider"BlockNameHere>, "getAspects")), I get the following error:

Update: Now I've got it outputting (in LUA) a Table: ####### followed by a 1 on the line below it. Thinking this might be going back to the above referenced issue of not identifying the provider correctly, but not sure what else I could name it.

Not sure what the problem is for this part. I think if I can crack this, the whole thing will work.. just not sure WHY this particular part is not working. Heh.


UPdate #2: I tried another command someone else listed elsewhere, specifying an actual aspect at the end (ie. terra). I have almost 900 terra in my system, however, it gave me a value of "0". So I'm wondering if for some reason the provider isn't recognizing the essentia in the network itself? I've tried both an Infusion Provider and Essentia Provider, making sure i have the one with the "getAspects" method available. My actual program when I run it comes back with an error now of "no such method getAmounts". The LUA command though is still giving:

table: 6a8c3fb4
1

(as an example. The sequence after table: changes).

Ideas? At my wits end at this point. Heh.
Edited on 01 April 2017 - 02:55 PM
andythornton #16
Posted 01 April 2017 - 07:02 PM
So here is what all I have currently:

The overall program is this Pastebin.

The current setup is this: I have the main screen with the computer to the left of it and the infusion provider below the computer. The provider is connected to the network from below.



When I do that LUA code referenced above: print(peripheral.call("bottom", "getAspects")), I get the table error:



Beyond that, I tried another command someone referenced in another thread of combining

a = peripheral.wrap("bottom")
a.getAspects()
type(a.getAspects())

and I get {} for the second command and "table" for the third command. I made sure I'm using the latest versions of Energistics (for 1.7.10 at least) as well as Computercraft, so… yeah, hitting a wall at this point. Not sure if its a compatibility issue or something else.

Edit: Also, if I run the overall program as is, I get an error: Aspects: 30: no such method getAmount
Edited on 01 April 2017 - 05:03 PM
Bomb Bloke #17
Posted 02 April 2017 - 01:55 AM
I get the table error

That's not an "error", that's the function doing its job and returning a result. The result is a pointer which leads to a table. You're asking Lua to specifically print out that pointer… and so it does.

This block here, on the other hand:

a = peripheral.wrap("bottom")
a.getAspects()

… does much the same thing, but since you're not specifically asking the Lua interpreter to print the return value of "a.getAspects()", it figures out for itself that it's more useful to serialise the table's content and display that instead. Because the table's empty, though, you end up seeing the definition for an empty table: "{}".

Why's the table empty? Your guess is as good as mine, I'm afraid; if you're sure that provider block is correctly connected to your network full of essentia, I'd expect you to get a fair bit more data back. Assuming you can confirm through other means that the essentia is accessible at that point, then I'd be inclined to blame a bug somewhere in your mod list.

This report looks like it may be related, but you may need to experiment a bit (test in a new world with minimal mods) and perhaps open up an issue of your own. Note that ComputerCraft itself doesn't provide any support for the aspect provider block - I'd assume that comes from Thaumic Energistics.

(If you do find yourself opening a new report, be sure to include all version numbers. No, "latest" is not a version number.)

I made sure I'm using the latest versions of Energistics (for 1.7.10 at least) as well as Computercraft, so… yeah, hitting a wall at this point. Not sure if its a compatibility issue or something else.

It's indeed at least partially a compatibility issue; Dire would've been using older versions. For whatever reason, he doesn't ever seem to document which ones.
andythornton #18
Posted 02 April 2017 - 02:32 AM
Gotcha. I updated a lot of the mods to the newest available for 1.7.10 (what the original Season 7 was running), so will go over some of the mods again and see what might be still "original" that could be causing the issue. I saw the report on issue #228, which prompted me to update a lot of the individual mods earlier this afternoon - without much luck afterwards so far. Will keep working on it though! :)/>