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

Thaumcraft 4.2.3.5 and Thaumic Tinkerer 2.5-491 Computercraft Script

Started by renjestoo, 13 June 2015 - 06:28 AM
renjestoo #1
Posted 13 June 2015 - 08:28 AM
Hey there, I have an issue with the DireWolf20 Essentia Script (for version 1.6.4). I almost get it to work but there is 1 explicit error:
Java Exception Thrown:
java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String

I know that the issue comes from line 68


os.loadAPI("button")
local essentia = {}
local jars = peripheral.getNames()
local m = peripheral.wrap("top")
local monCoord = {}
local currEssentia
local fillAmt = 0
local rowsActive = true
local c = peripheral.wrap("crystal_1")
local a = peripheral.wrap("tt_aspectanalyzer_3")
local f = peripheral.wrap("front ")
local redstoneDir = "back"
local beans = {}

function scanSlot(slot)
	c.pushItem("down", slot,1)
	data = a.getAspects()
	beans[data] = slot
	c.pullItemIntoSlot("down", 1, 1,slot)
end  

function scanSlots()
  redstone.setOutput(redstoneDir, true)
	for i = 1, 108 do
	  if c.getStackInSlot(i) then
	   scanSlot(i)
	  end
   end
   redstone.setOutput(redstoneDir, false)
end

function essentia(aspect, numAspect)
  if not f.getStackInSlot(1) then
	c.pushItemIntoSlot("front", beans[aspect], numAspect,1)
	redstone.setOutput("back", true)
	sleep(1)
	redstone.setOutput("back", false)
	sleep(3)
	--f.pullItemIntoSlot("down", 1, numAspect,1)  
  end
  while f.getStackInSlot(1) do
	print("Waiting for empty furnace....")
	sleep(3)
  end
  --   sleep(15)
end

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) == "tt_aspectContainer" then
	 asp = peripheral.call(j, "getAspects")
	 countasp = peripheral.call(j, "getAspectCount", 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
  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
  essData = textutils.unserialize(essData)
  m.clear()
  print(essData[1]..":"..essData[2])
  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.")
  essentia(essData[1], essData[2])
  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

scanSlots()
fillTable()
refresh()

while true do
getClick()
end

Some people say that it is because of the asp in line 67, but this is wrong.
When I perform the Command on line 68 on his own(without the asp on the end), I also get this error message.

The script needs to read out some data from the Jars from TT.
I did the following commands via LUA:
a = peripheral.wrap("tt_aspectContainer_0")
a.getAspects()

(Then I get the content of the jar)

when I perform the following:

a.getAspectCount()
(Then I get the error message: )

Java Exception Thrown: java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String


What can I do to solve this issue?

When I try to get the Methods on this peripheral, it states that he attempts to call nil.
So I can't check out the Methods of this Peripheral.

Kind Regards,
Renjestoo
Bomb Bloke #2
Posted 13 June 2015 - 09:31 AM
Line 68 of what you've posted reads:

  essentia[asp] = math.floor(countasp)

I guess you mean line 66?:

countasp = peripheral.call(j, "getAspectCount", asp)

What type is "asp"? I'm guessing table, whereas getAspectCount is probably going to what a string, yeah? Try print(type(asp)) immediately after setting it, and posting the exact output you got from a.getAspects() in the Lua console (all of it, verbatim).

Odds are you aren't getting your function list because you're doing something like a.getMethods() when you should be doing peripheral.getMethods("tt_aspectContainer_0").
renjestoo #3
Posted 13 June 2015 - 10:13 AM
Hmmmm, I can't figure out the way you mean it. Do you mean that I shoud edit the script with this? print(type(asp))
or just try it in LUA without the script.

I tried it in LUA, and it seems that I can't use a table????

Sorry if I am a little bit confused.
I can read scripts a little bit, but writing them myself completely is an impossible task for me :P/>.

Maybe you can help me out just a little bit more?
Bomb Bloke #4
Posted 13 June 2015 - 10:49 AM
In the Lua console, enter:

a = peripheral.wrap("tt_aspectContainer_0")
a.getAspects()  -- What EXACTLY does this display?
type(a.getAspects()) -- ... and what does this display?
renjestoo #5
Posted 13 June 2015 - 11:04 AM
okay


a = peripheral.wrap("tt_aspectContainer_0")
a.getAspects()   -- I get the Content of the jar where the aspects will be in
type(a.getAspects())  -- The only thing I see is "table"

So it seems that:

countasp = peripheral.call(j, "getAspectCount", asp)

can't read out the table it gets in the script with:

function scanEssentia()
    for i,j in ipairs(jars) do
        if peripheral.getType(j) == "tt_aspectContainer" then
            asp = peripheral.call(j, "getAspects")
            countasp = peripheral.call(j, "getAspectCount", asp)
            if countasp > 0 then
                essentia[asp] = math.floor(countasp)
            end
            --	   print(countasp)
            --	 print(asp..":"..countasp)
            --	 print(peripheral.getType(j))
        end
    end
end

when I use for example:

countasp = peripheral.call(j, "getAspectCount", "iter") -- One of the Aspects in TT
it seems to work.

But I want to read it out of a table.

How to do this?
Bomb Bloke #6
Posted 13 June 2015 - 11:25 AM
I don't think the "exact" screen output of that second command there is "I get the Content of the jar where the aspects will be in". I'm asking for what it shows you. Precisely. Verbatim. Sic. As it is written. Show me what it shows you.

Ideally, provide this twice - once for when the jar is empty, and once when it's full.
renjestoo #7
Posted 13 June 2015 - 11:43 AM
Aahhh okay, then I did't understand it correctly.

when the jar is Empty:

a.getAspects()
-- {}

When the jar is full:


a.getAspects()
-- {
--    "terra",
-- }

when performing this:


peripheral.call("tt_aspectContainer_2", "getAspectCount", "terra")
-- 64
Edited on 13 June 2015 - 09:45 AM
Bomb Bloke #8
Posted 13 June 2015 - 12:05 PM
That's much better.

It looks like you should be able to get away with changing this line in the scanEssentia() function:

asp = peripheral.call(j, "getAspects")     -- Set asp to the table the peripheral call returns.

… like so:

asp = peripheral.call(j, "getAspects")[1]  -- Set asp to the first entry in the table the peripheral call returns.

Though since we can assume attempting to count aspects in a jar with nothing in it won't work, and countasp will likely always be more than 0 if a jar contains an aspect, it might be worth re-doing the whole function:

function scanEssentia()
	for i,j in ipairs(jars) do
		if peripheral.getType(j) == "tt_aspectContainer" then
			asp = peripheral.call(j, "getAspects")[1]
			if asp then essentia[asp] = math.floor(peripheral.call(j, "getAspectCount", asp)) end
		end
	end
end
renjestoo #9
Posted 13 June 2015 - 12:19 PM
Ahhh well. It seems to work now. Now I have another issue :S :S

I get a message in the button API from Direwolf20
button:33: attempt to perform arithmetic on string.

this is the button API:

local mon = peripheral.wrap("top")
mon.setTextScale(1)
mon.setTextColor(colors.white)
local button={}
mon.setBackgroundColor(colors.black)
function clearTable()
   button = {}
   mon.clear()
end
			  
function setTable(name, func, xmin, xmax, ymin, ymax)
   button[name] = {}
   button[name]["func"] = func
   button[name]["active"] = false
   button[name]["xmin"] = xmin
   button[name]["ymin"] = ymin
   button[name]["xmax"] = xmax
   button[name]["ymax"] = ymax
end
function funcName()
   print("You clicked buttonText")
end
	  
function fillTable()
   setTable("ButtonText", funcName, 5, 25, 4, 8)
end	
function fill(text, color, bData)
   mon.setBackgroundColor(color)
   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
   for j = bData["ymin"], bData["ymax"] do
	  mon.setCursorPos(bData["xmin"], j)
	  if j == yspot then
		 for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
			if k == xspot then
			   mon.write(text)
			else
			   mon.write(" ")
			end
		 end
	  else
		 for i = bData["xmin"], bData["xmax"] do
			mon.write(" ")
		 end
	  end
   end
   mon.setBackgroundColor(colors.black)
end
	
function screen()
   local currColor
   for name,data in pairs(button) do
	  local on = data["active"]
	  if on == true then currColor = colors.lime else currColor = colors.red end
	  fill(name, currColor, data)
   end
end
function toggleButton(name)
   button[name]["active"] = not button[name]["active"]
   screen()
end	
function flash(name)
   toggleButton(name)
   screen()
   sleep(0.15)
   toggleButton(name)
   screen()
end
											
function checkxy(x, y)
   for name, data in pairs(button) do
	  if y>=data["ymin"] and  y <= data["ymax"] then
		 if x>=data["xmin"] and x<= data["xmax"] then
			data["func"]()
			return true
			--data["active"] = not data["active"]
			--print(name)
		 end
	  end
   end
   return false
end
	
function heading(text)
   w, h = mon.getSize()
   mon.setCursorPos((w-string.len(text))/2+1, 1)
   mon.write(text)
end
	
function label(w, h, text)
   mon.setCursorPos(w, h)
   mon.write(text)
end

Hope you can find the error?

PS: here is the link to the API:
http://pastebin.com/HRbMF1Eg
Edited on 13 June 2015 - 10:22 AM
Bomb Bloke #10
Posted 13 June 2015 - 01:09 PM
The button API you've got there doesn't appear to match whatever button API the main script was written for.

At a glance, you might be able to sort things out by changing these two functions like so:

function setTable(name, func, param, xmin, xmax, ymin, ymax)
   button[name] = {}
   button[name]["func"] = func
   button[name]["param"] = param
   button[name]["active"] = false
   button[name]["xmin"] = xmin
   button[name]["ymin"] = ymin
   button[name]["xmax"] = xmax
   button[name]["ymax"] = ymax
end

function checkxy(x, y)
   for name, data in pairs(button) do
          if y>=data["ymin"] and  y <= data["ymax"] then
                 if x>=data["xmin"] and x<= data["xmax"] then
                        data["func"](data["param"])
                        return true
                        --data["active"] = not data["active"]
                        --print(name)
                 end
          end
   end
   return false
end

… but there might be more to it than that.
renjestoo #11
Posted 13 June 2015 - 06:58 PM
Thanks in advice ;)/>
This worked… But……..
now I get again an error in the first script on line 50: bad argument: table expected, got function

function sortEss(t)
  local keys = {}
  for k in pairs(t) do keys[#keys+1] = k end
		table.sort(keys) -- its this line. It seems correct to me, but okay.... I am not a LUA specialist :P/>  --
		local i = 0
		return function()
		i = i+1
		if keys[i] then
		  return keys[i], t[keys[i]]
		end
  end
end
Edited on 13 June 2015 - 04:59 PM
Bomb Bloke #12
Posted 14 June 2015 - 02:30 AM
Looks to me like you're mixing up the line numbers again. It'll be this line that's failing:

for k in pairs(t) do keys[#keys+1] = k end

"t" is supposed to be the "essentia" table defined right up at the top of the script… but that's later overwritten with a function, for who knows what reason. Whoever published this version of the script you're using either didn't intend for it to be used, or they completely failed to test it out first - maybe they uploaded the wrong copy?

Find these two lines:

function essentia(aspect, numAspect)

  essentia(essData[1], essData[2])

… and change them like:

function cookEssentia(aspect, numAspect)

  cookEssentia(essData[1], essData[2])

… and expect further problems.
renjestoo #13
Posted 14 June 2015 - 01:32 PM
Hey I changed this and it seems to work. I get a screen with all my essentia and it looks fine.

However, when I want to add some essentia into the jars (via the touchscreen) I get the following message:

http://imgur.com/plPdK9I

it is in the 2nd line of this function of the textutils API:


function unserialize( s )
	local func = loadstring( "return "..s, "unserialize" )
	if func then
		setfenv( func, {} )
		local ok, result = pcall( func )
		if ok then
			return result
		end
	end
	return nil
end

now I really want to know what is triggering this API and function what is showing this error message

I hope you can help me with this once more. I know I am a burdain, but I really want this to work :D/>
Edited on 14 June 2015 - 11:33 AM
Bomb Bloke #14
Posted 14 June 2015 - 01:51 PM
function fillEss()
  local essData = {}
  essData[1] = currEssentia
  essData[2] = fillAmt
  essData = textutils.unserialize(essData)  -- Delete this line.
  .
  .
  .

At this point I'm quite curious as to where you got this script. I've taken a bit of a dig around, but can't seem to spot an exact match for it.
flaghacker #15
Posted 14 June 2015 - 02:41 PM
function fillEss()
  local essData = {}
  essData[1] = currEssentia
  essData[2] = fillAmt
  essData = textutils.unserialize(essData)  -- Delete this line.
  .
  .
  .

At this point I'm quite curious as to where you got this script. I've taken a bit of a dig around, but can't seem to spot an exact match for it.

Hey there, I have an issue with the DireWolf20 Essentia Script (for version 1.6.4).

Every program of Direwolf20 generates a flood of AAP threads because his scripts aren't really stable most of the time.
Bomb Bloke #16
Posted 14 June 2015 - 03:13 PM
Usually, though, the problems stem from his scripts making use of OpenPeripherals, which undergoes all sorts of changes with each release (largely because it has to deal with MineCraft and a slew of other mods changing). Trying to use them with the wrong builds results in missing function errors and whatnot, which is fair enough.

I don't think I've seen a DW20 script like this one before, though - it's simply broken. I mean, look at that last function I quoted. "Define essData as a table, then pass it to a function that tries to convert strings to tables." There are a lot of "this is a DW20 script modified by such-and-such" scripts out there, though, and I'm suspecting this was one of them.
renjestoo #17
Posted 14 June 2015 - 05:18 PM
this is a script from DireWolf20, but it is a combination of 2 scripts from him.

the only thing I now get is the following:
test:36: attempt to index ? (a number value)

its this line:
c.pushItemIntoSlot("front", beans[aspect], numAspect,1)

I don't know how to solve this :(/>
Please Help
Edited on 14 June 2015 - 03:19 PM
flaghacker #18
Posted 14 June 2015 - 06:26 PM
this is a script from DireWolf20, but it is a combination of 2 scripts from him.

the only thing I now get is the following:
test:36: attempt to index ? (a number value)

its this line:
c.pushItemIntoSlot("front", beans[aspect], numAspect,1)

I don't know how to solve this :(/>
Please Help

That explains a lot… Who combined those 2 scripts?

That error means "beans" is a number instead of a table. Could you upload you entire current code to pastebin? Then we'll able to give a better answer.
Edited on 14 June 2015 - 04:26 PM
renjestoo #19
Posted 14 June 2015 - 09:00 PM
Yeah sure, here it is:
http://pastebin.com/nx73P30i

The Button API is here:
http://pastebin.com/JxSCWTeA

Hope you can work it out for me
flaghacker #20
Posted 14 June 2015 - 09:32 PM
Yeah sure, here it is:
http://pastebin.com/nx73P30i

The Button API is here:
http://pastebin.com/JxSCWTeA

Hope you can work it out for me

I thing you got your line numbers mixed up again. Is it perhaps line 34 causing that error?

Could you try sticking a print statement right before that line?

print (beans)
Post the result here.
renjestoo #21
Posted 14 June 2015 - 09:57 PM
the restult is the following:
http://imgur.com/bvTILzD

PS: I changed the direction on line 35 from front to north. That was also an issue
renjestoo #22
Posted 14 June 2015 - 10:34 PM
Yeah sure, here it is:
http://pastebin.com/nx73P30i

The Button API is here:
http://pastebin.com/JxSCWTeA

Hope you can work it out for me

I thing you got your line numbers mixed up again. Is it perhaps line 34 causing that error?

Could you try sticking a print statement right before that line?

print (beans)
Post the result here.

the restult is the following:
http://imgur.com/bvTILzD

PS: I changed the direction on line 35 from front to north. That was also an issue
Bomb Bloke #23
Posted 15 June 2015 - 02:05 AM
Certainly not 24/7, if that's what you're expecting.

Let's see, line 34 in your paste:

c.pushItemIntoSlot("front", beans[aspect], numAspect,1)

Before that line, try printing "aspect", "numAspect", and "beans[aspect]".
renjestoo #24
Posted 15 June 2015 - 02:09 AM
Certainly not 24/7, if that's what you're expecting.

Okay sorry. I didn't know that. My excuses for that.
renjestoo #25
Posted 15 June 2015 - 02:15 AM
Certainly not 24/7, if that's what you're expecting.

Let's see, line 34 in your paste:

c.pushItemIntoSlot("front", beans[aspect], numAspect,1)

Before that line, try printing "aspect", "numAspect", and "beans[aspect]".

hmmmm, sadly this doesn't work
Bomb Bloke #26
Posted 15 June 2015 - 02:21 AM
That doesn't tell me anything useful.

Try:

function cookEssentia(aspect, numAspect)
        if not f.getStackInSlot(1) then
        print(aspect)
        print(numAspect)
        print(beans[aspect])
        c.pushItemIntoSlot("front", beans[aspect], numAspect,1)
        .
        .
        .

… and don't tell me what "doesn't" happen, tell me what "does"!
renjestoo #27
Posted 15 June 2015 - 02:51 AM
Okay, I will do this Step by step.
I added links to pictures from every step I took.
It should be rather easy to follow my issue now.

PS: Added the new and latest Script in the following link:
http://pastebin.com/qhFezYAP

This is the order I perform when testing this script.

Setup of my base:
http://imgur.com/SEgtwMd

Entering the command:
http://imgur.com/Hmi7Xo6

Result of entering command:
http://imgur.com/og1pyIk

Rightclick on essentia type:
http://imgur.com/m6LQUno

Result of rightclick:
http://imgur.com/MRjkiUW

PS: On this screen I rightclick on "Refill Jar" and then rightclick on "Execute Fill Request"
PSS: This also happens with the other options there are on the screen ;)/>


Result of the Request:
http://imgur.com/a/NvEET
Edited on 15 June 2015 - 12:53 AM
Bomb Bloke #28
Posted 15 June 2015 - 03:04 AM
Ok, that could be handy, but - the computer screen which shows the error (and, at this point, presumably the output of those print statements), what's that saying…?
renjestoo #29
Posted 15 June 2015 - 03:25 AM
Ok, that could be handy, but - the computer screen which shows the error (and, at this point, presumably the output of those print statements), what's that saying…?

Look at the last imgur link:
there are 2 pictures there. One showing the "touchscreen" and one showing the Console with the error.

when looking for all steps on the console, I made a new screenshot(there are outputs of every step I took made by the console):
http://imgur.com/danKIk7

Or is this not the thing you are asking for?
Bomb Bloke #30
Posted 15 June 2015 - 03:56 AM
Ah, that's the stuff! :)/>

That empty line before the error is where the script printed nil, indicating that it's "beans[aspect]" that the error's complaining about. Aspect's "terra", so apparently there's no "terra" key in the "beans" table.

This'll be because of line 17:

        data = a.getAspects()

As we were discussing on the last page, a.getApects() returns a table, and we're more interested in the first index of that table. So:

        data = a.getAspects()[1]
renjestoo #31
Posted 15 June 2015 - 04:06 AM
Ah, that's the stuff! :)/>

That empty line before the error is where the script printed nil, indicating that it's "beans[aspect]" that the error's complaining about. Aspect's "terra", so apparently there's no "terra" key in the "beans" table.

This'll be because of line 17:

		data = a.getAspects()

As we were discussing on the last page, a.getApects() returns a table, and we're more interested in the first index of that table. So:

		data = a.getAspects()[1]


YESSS this is what I wanted :D/> :D/> :D/> Its working perfect.
I'm gonna test some more and report if there are more issues. Probably minor issues which should be adding some failsafe lines
renjestoo #32
Posted 15 June 2015 - 04:37 AM
The script is finaly fully functioning perfectly.
You can download the script in Computercraft with:
"pastebin get g4KzWGJK AutoEssence"

For the button API type this:
"pastebin get GNKKtzdE button1"


If you want, you can share this script with other people. This is a working script that is automatically refreshing all the aspects on the screen after a request.

The setup is the following:
http://imgur.com/SEgtwMd

This script is working for Thaumcraft 4.2.3.5 and Thaumic Tinkerer 2.5-491

I really appreciate you're help Bomb Bloke

I know there are a lot of people who wanted this script to fully work without issues.
Now there is a updated version of the script :D/> :D/> :D/>
Edited on 17 June 2015 - 12:41 PM