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

TC smeltery

Started by Dustmuz, 13 December 2014 - 05:38 PM
Dustmuz #1
Posted 13 December 2014 - 06:38 PM
Hello

after reading this, i hoped to be able to "control" my smelteries with a computer.

but when i tried the textutils.tabulate(peripheral.getMethods("right")) *where my smeltery is*
i got nothing..
no table no nothing..

does any of you know if Smelteries are supported in 1.7.10?

happy christmas and hopefully a good new year aswell :)/>
The_Cat #2
Posted 13 December 2014 - 07:04 PM
I'm not 100% sure but I think this only works with 1.6.4 and lower. I tried a similar thing but with getting information from a tank with how much lava is in it. :/
Edited on 13 December 2014 - 06:04 PM
Dustmuz #3
Posted 13 December 2014 - 08:41 PM
okay.. would have been "cool" to control the smeltery from a comp..

thanks for the answer :)/>
Dragon53535 #4
Posted 13 December 2014 - 08:43 PM
As far as I can see, openperipherals in 1.7.10 does not support it. Perhaps we just have to wait longer for them to add it?
Lyqyd #5
Posted 13 December 2014 - 09:23 PM
If you're looking for liquid sensing, you might try the latest build of OpenCCSensors. The 1.7.10 build can be found on the last page of its topic in the Peripheral section, in one of my posts near the bottom of the page.
Dustmuz #6
Posted 13 December 2014 - 09:45 PM
If you're looking for liquid sensing, you might try the latest build of OpenCCSensors. The 1.7.10 build can be found on the last page of its topic in the Peripheral section, in one of my posts near the bottom of the page.

ohh sounds interesting :D/> will have to check this out..

building a "small" city in SSP, and hoping to make a central hub for everything..
using computers with wireless modems, to control everything.. so far, i got the light and mana production made :D/>
Dustmuz #7
Posted 14 December 2014 - 10:07 AM
now..
i got my hands on OpenCCsensors
great mod, with lots of great possibilities..
so a lot of Thanks Lyqud for that mod, remember to Thank the other guys that made it aswell :)/>

except im dumb as a flowerpot :P/> hehe (i'll admit that when it comes to tables"

how is it, that i print a table
i know how to get it to show what the things is

for key,value in pairs(p.getTargets()) do
print(key.." - "..type(value))
end

that tells me that there are 2 tables..
when i then just try the "same" but with..value) instead of ..type(value))

i get an error
attemt to cencatenate string and table..

im lost, as my skype is down atm so cant ask my usual "guy" hehe



what im trying to do, is make the program register the content of my smeltery that is on the right side of the computer, and sensor is ontop of the computer
Edited on 14 December 2014 - 09:08 AM
Lyqyd #8
Posted 14 December 2014 - 11:40 AM
You might try doing something like:


print(textutils.serialize(value))

That should make a human-readable version of the table information. Mainly, though, you're going to want to use the keys from the table returned by the getTargets call as the argument for the getTargetDetails call. You can see what getTargetDetails returns for each target by using the sensorview program (/ocs/programs/sensorview).
Dustmuz #9
Posted 14 December 2014 - 11:44 AM
i found the sensor view program :D/> hehe.. very nice program to be honest :)/>

will try and fiddle with the serialize(value) and see what it comes up with :)/>


EDIT: just tried the print(textutils.serialize(value))
it gives me all the info i need it seems.
but there is a but.. hehe..
theres more info than there can be on the screen..
so i wrote it all to a file using the fs api..

next thing is..


the table is build up like this:
rawname
temperature
name
luminousity
viscosity
amount
capacity
isGaseous

theres a table in the table..
so to get into the "second" table, i would do

print(value[1])

I tried doing this, but it gave me a blank line.


what am i doing wrong.. tables isnt exactly my thing, cant get my head around those damn things :(/>
Edited on 14 December 2014 - 11:00 AM
Bomb Bloke #10
Posted 14 December 2014 - 12:14 PM
I would've expected textutils.serialize() to deal with nested tables (that is to say, tables in your table).

But let's say you wanted to print the value of "rawname" inside your "value" table. You'd either print value["rawname"], or value.rawname.

You might find it useful to read this guide, and perhaps this thread.
Dustmuz #11
Posted 14 December 2014 - 12:21 PM
Bomb Bloke
print(value["rawname"]) - empty line
print(value.rawname) - empty line

to say the least, Tables, arent exactly my thing.. i do really "hate" them, and if i could erase them from existence, i would :D/> hehe<
tried reading those "tutorials" before, even had Dragon53535 give me a "tutorial" step by step through them on skype, i got a little smarter, but i still lack about 98% of the knowledge to use tables :D/>
Dustmuz #12
Posted 14 December 2014 - 12:28 PM
just to show the full code im using so far

local p = peripheral.wrap("top")

for key,value in pairs(p.getTargets())
something = fs.open("text","w")
something.write(value)
something.close()
end



thats the entire code so far.. just messing around with it, to figure out how to access the tables
Bomb Bloke #13
Posted 14 December 2014 - 01:07 PM
A problem with your code is that every time you open "text" in write mode, you erase whatever was already in it. You open the file once for every entry in the table, so the end result will only contain the name of the last entry you iterated through.

Going back to textutils.serialize(), try this:

textutils.pagedPrint(textutils.serialize(peripheral.call("top","getTargets")))

… or this:

local myFile = fs.open("text","w")
myFile.write(textutils.serialize(peripheral.call("top","getTargets")))
myFile.close()

Take a look at the result, then take another look at that second link I provided above.
Dustmuz #14
Posted 14 December 2014 - 01:43 PM
The first one game me a lot of info, in a scrolling "message"

using the myfile solution..
gave me some more info to the text file..

thanks a lot on that part Bomb :)/>



to the thread you linked to..
looking at the solution in first post
have absolutely no idea what on earth happens where..

1 line: creating func
2 line: creating a table
3 line, and im lost
4 line. the results of "function" is put into a variable
5 and forward completely lost

so.. im pretty lost when it comes to the tables, have no idea on how to work with them, also why i try my very best to avoid those in my own programming.
Bomb Bloke #15
Posted 14 December 2014 - 09:50 PM
If you copy and paste the results from your "text" file here, someone should be able to explain how to make use of them.
Lyqyd #16
Posted 15 December 2014 - 07:02 AM
Bear in mind also that Lua is case sensitive, so if you see "RawName" in sensorview, you're going to need to index "RawName", not "rawname" to get what you want out of it.
Dustmuz #17
Posted 15 December 2014 - 12:04 PM

{
  [ "-2,-1,4" ] = {
	Tanks = {
	  {
		RawName = "fluid.tile.lava",
		Temperature = 1300,
		Name = "lava",
		Luminousity = 15,
		Viscosity = 6000,
		Amount = 3820,
		Capacity = 4000,
		IsGaseous = false,
	  },
	},
	DamageValue = 0,
	Position = {
	  Y = -1,
	  X = -2,
	  Z = 4,
	},
	RawName = "tconstruct.seared tank",
	Name = "Seared Tank",
  },
  [ "-2,-1,0" ] = {
	Tanks = {
	  {
		RawName = "fluid.iron.molten",
		Temperature = 1300,
		Name = "iron.molten",
		Luminousity = 12,
		Viscosity = 6000,
		Amount = 2592,
		Capacity = 2592,
		IsGaseous = false,
	  },
	  {
		Capacity = 10368,
		Amount = 0,
	  },
	},
	DamageValue = 1,
	Position = {
	  Y = -1,
	  X = -2,
	  Z = 0,
	},
	RawName = "tconstruct.smeltery drain",
	Name = "Smeltery Drain",
  },
}


thats what i get in my textfile.

the "things" i would like to pull out of it, is the #.molten (name) and the amount of that fluid.
in this case i used iron to test it with..

i hope i can make (with help) a working code

i can see the name of the table i need to get "into" is

"-2,-1,0" - Tanks - and then get the info


would this give me the info i need??


print(["-2,-1,0]["Tank"]["Name]
Edited on 15 December 2014 - 10:59 AM
Lyqyd #18
Posted 15 December 2014 - 03:54 PM

os.loadAPI("ocs/apis/sensor")
local sense = sensor.wrap("top")

local details = sense.getTargetDetails("-2,-1,0")
print(details.Tanks[1].RawName)

The above would be the most correct way of retrieving the information you want. I'm not sure the getTargets call should be returning all of the information you posted above, but the getTargetDetails call will always give you that information, if available.
Dustmuz #19
Posted 15 December 2014 - 05:44 PM

os.loadAPI("ocs/apis/sensor")
local sense = sensor.wrap("top")

local details = sense.getTargetDetails("-2,-1,0")
print(details.Tanks[1].RawName)

The above would be the most correct way of retrieving the information you want. I'm not sure the getTargets call should be returning all of the information you posted above, but the getTargetDetails call will always give you that information, if available.

So with this, i should be able to just change Rawname with amount and get the amount aswell?

because if it is "that easy" i might have the program done in a few hours :D/>
KingofGamesYami #20
Posted 15 December 2014 - 06:16 PM
-snip-
So with this, i should be able to just change Rawname with amount and get the amount aswell?

because if it is "that easy" i might have the program done in a few hours :D/>/>

"Amount" with a capital "A", yes.
Dustmuz #21
Posted 15 December 2014 - 06:23 PM
-snip-
So with this, i should be able to just change Rawname with amount and get the amount aswell?

because if it is "that easy" i might have the program done in a few hours :D/>/>

"Amount" with a capital "A", yes.

okayokay :D/> hehe. will remember the capital A..

But thanks a lot for the help.. :)/>

- removed for out of bounds purpose with no exceptions :D/>

thanks for the help with this :)/>
Dustmuz #22
Posted 16 December 2014 - 03:27 AM
Now "we" ran into problems again :D/> hehe

Dragon53535 and i been working at this code for a few hours, trying to get it to work correctly, but it "misscounts" somewhere.
and we cant find the problem..
so i decided to ASK FOR HELP :D/>

could you guys, have a look at the code, and see what we have done wrong, since it wont work properly..

the setup is as seen in the pictures
smelting command is sent from a wireless pocket computer

Spoiler

os.loadAPI("ocs/apis/sensor")
local modem = peripheral.wrap("bottom")
local wireless = peripheral.wrap("front")
wireless.open(1)
local comp
for a,v in pairs(modem.getNamesRemote()) do
  if peripheral.getType(v) == "computer" then
	comp = peripheral.wrap(v)
	break
  end
end
local blocksize = 1296 --mb pr block
local ingotsize = 144 --mb pr ingot
local blocks = 0
local ingot = 0

local sense = peripheral.wrap("top")

local function basin()
  while blocks ~= 0 do
	rs.setOutput("left", not rs.getOutput("left"))
	sleep(17)
	blocks = blocks-1
  end
end

local function cast()
  comp.shutdown()
  while ingot ~= 0 do
	comp.turnOn()
	sleep(5)
	comp.shutdown()
	sleep(1)
	ingot = ingot - 1
  end
end	  

while true do
  local event = {os.pullEvent("modem_message")}
  if event[5] == "smelterybegin" then
	local details = sense.getTargetDetails("0,-1,1")

	for a,v in ipairs(details.Tanks) do
	  if v.Name then
		local st = string.find(v.Name,".molten")
		local name = string.sub(v.Name,1,st-1)
		blocks = math.floor(v.Amount / blocksize)
		ingot = math.floor((v.Amount % blocksize) / ingotsize)
		parallel.waitForAll(basin,cast)
	  end
	end
	wireless.transmit(1,1,"done")
	rs.setOutput("left",false)
  end
end

Edited on 16 December 2014 - 02:28 AM
Dragon53535 #23
Posted 16 December 2014 - 11:03 PM
To put a little information into the post.

When we run the program, it calculates the blocks and ingots correctly.
We ran the program only with blocks working, and it seemed that the drain it was connected to would pour if there was a change in redstone state, on or off. We ran it for a bit with that on, and it poured out the correct amount of blocks.
However when we reconnected the ingot part (Which is just a computer with a startup script of turning on a redstone signal for the other drain.) it didn't work correctly.

Before we swapped it so that it changed it's state, it would pour a full block into the basin, and then start just pouring ingots in at a time, until it thought it poured enough "blocks". When we looked at it with only blocks pouring, we were able to tell that it did it over state changes and fixed it accordingly, however it seems that somehow we're wrong in that regard as it only pours a block every other block now.
ByteMe #24
Posted 17 December 2014 - 03:36 AM
Maybe the math is wrong or the terms are being specified after the math? I'm not entirely sure
Bomb Bloke #25
Posted 17 December 2014 - 09:33 AM
I'm no expert on TC - I've only once or twice played with a furnace that someone else on my server built, so I've only got a grasp of the very basics - but a couple of things stand out at me.

First off, I'm assuming your reason for using ipairs on details.Tanks is because the tank can hold multiple types of molten resources at a time. But, is the order in which the sensor presents those resources the order in which the furnace will create blocks/ingots with them? You'll run into problems if for whatever reason it's not.

Then there's the rs.setOutput("left", not rs.getOutput("left")) business. Assuming that works, why do you then have a rs.setOutput("left",false) later in the script? Wouldn't that potentially conflict by eg pouring a partial block?
Dustmuz #26
Posted 17 December 2014 - 11:00 AM
First off, I'm assuming your reason for using ipairs on details.Tanks is because the tank can hold multiple types of molten resources at a time. But, is the order in which the sensor presents those resources the order in which the furnace will create blocks/ingots with them? You'll run into problems if for whatever reason it's not.

i can asnwer a little of this :D/>
the smeltery can hold as many kinds of metals, as theres room..
so you could have all different kinds of metals in there..

we tested this with 1 and 2 different metals in the smeltery, and at both setups it poured out ingots into the basin, instead of the casting table.
for the "listing" of the metals, it made that "right" so far as i could tell, when we had both gold and iron in the smeltery..

but even when we only had iron OR gold, it still messed up the pouring.


for the rs.setOutput business, i will leave that to Dragon, as he has a better understanding, and is better at explaining this :)/>

[
Edited on 17 December 2014 - 10:01 AM
Dragon53535 #27
Posted 17 December 2014 - 05:24 PM
This system was designed to pour out the entire contents of the smeltery (Unless for whatever reason it had nuggets or whatever) And so at the end, turning the signal to false at the end was a precautionary measure since the smeltery should be empty so that should the computer turn off, I'd rather it not pour another block because of the redstone change.


Perhaps though, we cannot actually do this. Perhaps it is the smeltery that is stopping us and doesn't let 2 spots pour at once… I'll confirm with Dustmuz about this
Edited on 17 December 2014 - 04:25 PM
Bomb Bloke #28
Posted 17 December 2014 - 09:59 PM
To my memory, the three faucets of the smeltery I played with (plates, ingots and blocks) did work at the same time. They continued to pour so long as a redstone signal was applied.
Dustmuz #29
Posted 17 December 2014 - 10:14 PM
Bomb..

so its more of a timer we need to make, and know the exact amount of time, we need to apply a redstone signal for a block/ingot, if you think that would work instead??
Bomb Bloke #30
Posted 18 December 2014 - 04:33 AM
I'd assume so. I'm sorta thinking that the only reason your current block-pouring code works at all is because when it turns the signal on, it leaves it that way long enough to cause two full blocks to be poured (I assume that once pouring of a block starts, it continues even if the signal is removed - thus if it takes eg 15 seconds to pour a block, leaving the signal on for 16 seconds would get you two).

Stick a regular lever next to the block faucet and experiment with that, I guess.