This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
How to prevent this
Started by Metalhawk2012, 29 May 2015 - 10:17 PMPosted 30 May 2015 - 12:17 AM
==========================Post Reopened Read Last Post!!!==================================
Edited on 13 February 2016 - 01:19 AM
Posted 30 May 2015 - 12:29 AM
Maybe consider labeling the PCs, this way they won't loose the ids.
Posted 30 May 2015 - 12:37 AM
Do I understand correctly, that the original computer displays correctly, but the second computer displays one row lower? If so, what happens with a 3rd computer? Please post your code, I'm curious how you're formatting your output.… but when i add another computer running the same code the information gets "moved" down one row, i have to go into my minecraft folder and remove the lastId.txt to fix
is there anyway to sort this without deleting the lastid.txt?…
Posted 30 May 2015 - 12:40 AM
Do I understand correctly, that the original computer displays correctly, but the second computer displays one row lower? If so, what happens with a 3rd computer? Please post your code, I'm curious how you're formatting your output.… but when i add another computer running the same code the information gets "moved" down one row, i have to go into my minecraft folder and remove the lastId.txt to fix
is there anyway to sort this without deleting the lastid.txt?…
Yeah Sure Here's the code And the 3rd,4th 5th .ect will display 1 row lower then the previous computer on the same network
local drums = peripheral.getNames()
local monitor = peripheral.wrap("right")
monitor.setTextScale(0.5)
monitor.clear()
function scanDrum()
for i,d in pairs(drums) do
if peripheral.getType(d) == "drum" then
info = peripheral.call(d,"getTankInfo")
t1 = info[1]
capacity = t1.capacity
amount = t1.contents.amount
fill = math.floor(amount*100/capacity)
if fill <=20 then color = colors.red end
if fill <50 and fill>20 then color = colors.yellow end
if fill <75 and fill>=50 then color = colors.orange end
if fill >=75 then color = colors.green end
monitor.setCursorPos(1,i-1)
monitor.setTextColor(colors.green)
monitor.write("Name: "..t1.contents.rawName)
monitor.setCursorPos(30,i-1)
monitor.setTextColor(colors.red)
monitor.write("Amount: "..t1.contents.amount)
monitor.setCursorPos(47,i-1)
monitor.setTextColor(colors.blue)
monitor.write("Capacity: "..t1.capacity)
monitor.setCursorPos(66,i-1)
monitor.setTextColor(color)
monitor.write(fill.."% Full")
end
end
end
while true do
sleep(0.1)
scanDrum()
end
Edited on 29 May 2015 - 10:41 PM
Posted 30 May 2015 - 12:54 AM
Are the modems on the computers themselves turned on or off? They *should* be off. I have a feeling that the computers are being detected and one of your computers is seeing the drums as items 2-5 instead of items 1-4. That's my only guess, atm.
Posted 30 May 2015 - 12:56 AM
i understand what you mean i havent had much experience with computercraft much i always thought that the modem had to be on for it to actually see whats in the networkAre the modems on the computers themselves turned on or off? They *should* be off. I have a feeling that the computers are being detected and one of your computers is seeing the drums as items 2-5 instead of items 1-4. That's my only guess, atm.
Just tried it and no that didn't seem to work there's still a empty row. do you think this could be the monitor?
Edited on 29 May 2015 - 10:58 PM
Posted 30 May 2015 - 01:03 AM
I don't have a way of testing atm but I guess it *could* be the monitor. However, only the bottom computer is touching both monitor arrays and it is displaying correctly, right? Do I understand correctly that the top computer is displaying incorrectly?
Oh, and just to cover all the obvious bases…you did restart the programs after turning off the computer modems, right?
Oh, and just to cover all the obvious bases…you did restart the programs after turning off the computer modems, right?
Edited on 29 May 2015 - 11:07 PM
Posted 30 May 2015 - 01:13 AM
I don't have a way of testing atm but I guess it *could* be the monitor. However, only the bottom computer is touching both monitor arrays and it is displaying correctly, right? Do I understand correctly that the top computer is displaying incorrectly?
Oh, and just to cover all the obvious bases…you did restart the programs after turning off the computer modems, right?
Yeah i did, ive now gone into a test world but it still seems to be a empty row on pos(1,1)
ive put the value of "i" next to the name which should correspond the drum number and the row number as you can see 2-6 are there but wheres 1?? it must be the monitor and the code is displaying it as a empty string
Edited on 29 May 2015 - 11:13 PM
Posted 30 May 2015 - 01:23 AM
It could be the monitor. First - which monitor in your original setup is displaying incorrectly? Top or bottom? I'm guessing top. If that's the case, then the monitor doesn't make sense since only the bottom computer is touching both monitor arrays.
Let's find out what the computer is seeing. Run this on each system and let's see what's different…
Let's find out what the computer is seeing. Run this on each system and let's see what's different…
local perps = peripheral.getNames()
for k, v in pairs(perps) do
print(k .. " / " .. v)
end
Posted 30 May 2015 - 01:30 AM
Computer 1 brings up
1 top
2 back
3 drum_0
4 drum_2
5 drum_1
6 drum_4
7 drum_3
8 right
Computer 2
1 back
2 drum_0
3 drum_2
4 drum_1
5 drum_4
6 drum_3
7 right
So now we know its the monitors how can we filter them out?
1 top
2 back
3 drum_0
4 drum_2
5 drum_1
6 drum_4
7 drum_3
8 right
Computer 2
1 back
2 drum_0
3 drum_2
4 drum_1
5 drum_4
6 drum_3
7 right
So now we know its the monitors how can we filter them out?
Edited on 29 May 2015 - 11:35 PM
Posted 30 May 2015 - 01:39 AM
Well, there are a number of approaches you can use. Here are two off the top of my head:
1. Use a separate variable for y position instead of using i, increment as necessary
2. Filter the results before processing them
1. Use a separate variable for y position instead of using i, increment as necessary
local yPos = 1
... code ...
monitor.setCursorPos(1, yPos)
monitor.write("Stuff")
yPos = yPos + 1
2. Filter the results before processing them
local drums = peripheral.getNames()
for i = #drums, 1, -1 do
if peripheral.getType(drums[i]) ~= "drum" then
table.remove(drums, i)
end
end
Posted 30 May 2015 - 01:56 AM
Thank you!!! the 2nd code works perfectly thanks i can now be able to have multiple computers on that network as you can see with this picture, again thanks
Posted 30 May 2015 - 01:57 AM
You're very welcome. Glad I could help :)/>
Posted 30 May 2015 - 02:03 AM
local drums = peripheral.getNames()
local monitor = peripheral.wrap("right")
for i = #drums,1,-1 do
if peripheral.getType(drums[i]) ~= "drum" then
table.remove(drums,i)
end
end
monitor.setTextScale(0.5)
monitor.clear()
function scanDrum()
for i,d in pairs(drums) do
if peripheral.getType(d) == "drum" then
info = peripheral.call(d,"getTankInfo")
t1 = info[1]
capacity = t1.capacity
amount = t1.contents.amount
fill = math.floor(amount*100/capacity)
if fill <=20 then color = colors.red end
if fill <50 and fill>20 then color = colors.yellow end
if fill <75 and fill>=50 then color = colors.orange end
if fill >=75 then color = colors.green end
monitor.setCursorPos(1,i)
monitor.setTextColor(colors.green)
monitor.write("Name: "..t1.contents.rawName.." "..i)
monitor.setCursorPos(30,i)
monitor.setTextColor(colors.red)
monitor.write("Amount: "..t1.contents.amount)
monitor.setCursorPos(47,i)
monitor.setTextColor(colors.blue)
monitor.write("Capacity: "..t1.capacity)
monitor.setCursorPos(66,i)
monitor.setTextColor(color)
monitor.write(fill.."% Full")
end
end
end
while true do
sleep(0.1)
scanDrum()
end
That's what this "Ask a pro" forum is for ^^oh and feel free to use the code if you need to it was a little project i wanted to do for my base on my sp world
Edited on 30 May 2015 - 12:10 AM
Posted 13 February 2016 - 02:18 AM
Its Been a while since i last had this post up, but i require a little help when adding an empty barrel to the system, obviously when a new barrel is added it tries to output its contents(which is obviously doesnt have) so i get a nil value error, is there a way to run a code when a nil value is detected?
Posted 13 February 2016 - 02:55 AM
You have to start checking if things are nil before using them. For example;
info = peripheral.call(d,"getTankInfo")
t1 = info[1]
capacity = t1.capacity
--#here I use a two ternary operators to avoid indexing t1.contents if it is nil
--#psudocode: IF (t1.contents) THEN amount = t1.contents.amount ELSE amount = 0
amount = (t1.contents and t1.contents.amount) or 0
fill = math.floor(amount*100/capacity)
Edited on 13 February 2016 - 01:55 AM
Posted 13 February 2016 - 01:34 PM
You have to start checking if things are nil before using them. For example;info = peripheral.call(d,"getTankInfo") t1 = info[1] capacity = t1.capacity --#here I use a two ternary operators to avoid indexing t1.contents if it is nil --#psudocode: IF (t1.contents) THEN amount = t1.contents.amount ELSE amount = 0 amount = (t1.contents and t1.contents.amount) or 0 fill = math.floor(amount*100/capacity)
That worked, cheers, i just had to do it with the capacity, name, and fill because i also kept getting nil values from them too
capacity = (t1.contents and t1.capacity) or "0 "
amount = (t1.contents and t1.contents.amount) or "0 "
rawName = (t1.contents and t1.contents.rawName) or "Empty Barrel"
fill = (t1.contents and t1.capacity and math.floor(amount*100/capacity)) or 0