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

[tekkit]8monitors displays all info. [Tables/data]

Started by Goof, 28 March 2013 - 08:01 PM
Goof #1
Posted 28 March 2013 - 09:01 PM
Hi:D

EDIT: Sorry.. the [code.] tags didnt indent the code

im on a tekkit server with my friend, and he asked me to make list above all our chests, which contains "Copper", "Tin" etc. but.
im a bit tired right now, and cant figure out, how to do this automatically.



local mon = peripheral.wrap("left")
local length = mon.getSize()
local sp = mon.setCursorPos
local w = mon.write

function getData()
data = fs.open("data", "r")
data.readAll()
data.close()
end
function saveData()
data1 = fs.open("data", "w")
for i = 1, #data do
fs.writeLine(data[i])
end
data1.close()
end

local ores = {
		[1] = { ['Copper'] = 32,
		['Iron'] = 32,
		['Gold'] = 32, } -- monitor 1 (above the 1 chest, should print "Copper", Iron, Gold --
		-- all of them ... (8 monitors at all)
}
local mon = peripheral.wrap('left')

for i, v in pairs( ores ) do
sp(v,v)
w(v)
end


could anyone please help me making that to happen?

more information comming soon
screenie:
Spoiler
all the signs on this screenshot, is what i want to be monitors.

old code:(my first attempt)


local mon = peripheral.wrap("left")
local length = mon.getSize()
local sp = mon.setCursorPos
local w = mon.write

function getData()
data = fs.open("data", "r")
data.readAll()
data.close()
end
function saveData()
data1 = fs.open("data", "w")
for i = 1, #data do
fs.writeLine(data[i])
end
data1.close()
end

local ores = {
		[1] = { ['Copper'] = 32,
		['Iron'] = 32,
		['Gold'] = 32, } -- monitor 1 (above the 1 chest, should print "Copper", Iron, Gold --
		-- all of them ...
}
local mon = peripheral.wrap('left')
-- this is what i did, quickly. but that is what i want to be automated. (checking the ores table and printing the containing data)
sp(1,1)
w(ores[1][1])
sp(1,2)
w(ores[1][2])
sp(1,3)
w(ores[1][3])
-- etc...




thanks in advance
Goof #2
Posted 29 March 2013 - 12:57 AM
Any help?

Please

Quick screenie of the result with "my first attempt"
LordIkol #3
Posted 29 March 2013 - 03:01 AM
hi Mikk,

From what i get you want to use the Monitors instead of a Sign?

If i got it correct you want sth that does this things
1. Write a Setup file like "monitor 1 = Tin Copper Silver Monitor 2 = Gold Iron Diamon etcc
2. a File that can Load this setup and display the Data on the correct Monitor

did i get it right?
Goof #4
Posted 29 March 2013 - 03:16 AM
Yup… but i actually got all the program to work… EXCEPT that save, and read part… my code is the following… (look for the few comments on saveData, and getData)
Spoiler

local mon = peripheral.wrap("left")
local length = mon.getSize()
local sp = mon.setCursorPos
local w = mon.write

rednet.open("top")
term.clear()
term.setCursorPos(1,1)
print(os.getComputerID())
mon.clear()
mon.setCursorPos(1,1)

local ores = {
	[1] = {"Copper","Iron","Gold"};
	[2] = {"Silver","Ruby","Emerald","Sapphire"};
	[3] = {"Diamond","DarkMatter","RedMatter","Tungsten"};
	[4] = {"Tin","Brass"}
	  

					   -- all of them ...
}

function getData() --and i think its because its saved uncorrect, its throwing errors, like : bad argument, table expected, got string.
	data = fs.open("data", "r")
	readDat = data.readAll()
	ores = textutils.unserialize(readDat)
	data.close()
end
function saveData(tab) -- This saveData saves only one huge string. (""{[1]={[1]=\"Tin\",[2]=\"Copper\",[3]=\"Silver\",},[2]={[1]=\"Diamond\",[2]=\"Iron\",[3]=\"Gold\",},[3]={[1]=\"Tungsten\",[2]=\"RedMatter\",[3]=\"DarkMatter\",},[4]={[1]=\"Crap\",},[5]={[1]=\"Other\",[2]=\"Stuffs\",},}"") -- thats what the "data" file holds... but i just wanted this function to save the whole table on several lines ( like when you look at the table now ), instead of a whole string in 1 line.
	data1 = fs.open("data", "w")
	x = textutils.serialize(tab)
		data1.write(x)
	data1.close()
end

local mon = peripheral.wrap('left')

if fs.exists("data") then
getData()
end
function setPos(x,y)
	if x == 1 then
		xp = 1
	elseif x == 2 then
  xp = 10
elseif x == 3 then
  xp = 21
elseif x == 4 then
  xp = 32
elseif x == 5 then
  xp = 43
elseif x == 6 then
  xp = 54
elseif x == 7 then
  xp = 65
elseif x == 8 then
  xp = 76	
elseif x == 9 then
  xp = 87
	elseif x == 10 then
  xp = 98
elseif x == 11 then
  xp = 109
end
	mon.setCursorPos(xp,y)
end
for i, v in pairs( ores ) do
	for yp = 1, #v do
		setPos(i,yp)
		w(v[yp])
	end	
		-- math to get correct spot to write the correct text
end
while true do
	-- updater --
	id, msg = rednet.receive()
	ores = msg
	saveData(ores)
	
	
end	


but, everything you said, is correct
Goof #5
Posted 29 March 2013 - 06:16 AM
Ehm.. im sorry to say, but after several hours of thinking/coding, i've found an idea: (this post is now solved)
Spoiler

local mon = peripheral.wrap("left")
local length = mon.getSize()
local sp = mon.setCursorPos
local w = mon.write

rednet.open("top")
term.clear()
term.setCursorPos(1,1)
print(os.getComputerID())
mon.clear()
mon.setCursorPos(1,1)

local ores = {
	[1] = {"Copper","Iron","Gold"};
	[2] = {"Silver","Ruby","Emerald","Sapphire"};
	[3] = {"Diamond","DarkMatter","RedMatter","Tungsten"};
	[4] = {"Tin","Brass"}
	  

                       -- all of them ...
}

function getData()
	data = fs.open("data", "r")
	readDat = data.readLine()
	ores = textutils.unserialize(readDat)
	data.close()
	return ores
end
function saveData(t)
	data1 = fs.open("data", "w")
	tab = textutils.serialize(t)
		data1.write(tab)
	data1.close()
end

local mon = peripheral.wrap('left')

if fs.exists("data") then
	ores = getData()
	sleep(2)
end
function setPos(x,y)
	if x == 1 then
		xp = 1
	elseif x == 2 then
		xp = 10
	elseif x == 3 then
		xp = 21
	elseif x == 4 then
		xp = 32
	elseif x == 5 then
		xp = 43
	elseif x == 6 then
		xp = 54
	elseif x == 7 then
		xp = 65
	elseif x == 8 then
		xp = 76    
	end
	mon.setCursorPos(xp,y)
end
for i, v in pairs( ores ) do
	for yp = 1, #v do
		setPos(i,yp)
		w(v[yp])
	end	
		-- math to get correct spot to write the correct text
end
while true do
	-- updater --
	id, msg = rednet.receive()
	ores = textutils.unserialize(msg)
	saveData(ores)
	
	
end	



Thanks helping me :D/>