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

OpenPeripherals Sensor

Started by RedstonersElite, 23 November 2014 - 03:35 AM
RedstonersElite #1
Posted 23 November 2014 - 04:35 AM
Can someone please tell me how I can make the computer not print if there are no players nearby?

glass = peripheral.wrap("right")
p = peripheral.wrap("left")
a = p.getPlayerNames()
glass.clear()
glass.addBox(1,1,100,50,0xFFFFFF,0.2)
c = 4
while true do
if c == 44 then
glass.clear()
glass.addBox(1,1,100,50,0xFFFFFF,0.2)
c = 4
end
sleep(3)
a = p.getPlayerNames()
for i=1,#a do
glass.addText(2, c, a, 0x000000)
end
c = c + 8
end

If there are no players nearby it just prints a blank space. I want it to print just player names and nothing extra
Bomb Bloke #2
Posted 23 November 2014 - 05:51 AM
It's not that it "prints a blank space", rather it's that "c" keeps incrementing and resetting regardless as to whether anything was printed.

It sounds like you only want to increase "c" if #a > 0.
RedstonersElite #3
Posted 23 November 2014 - 05:55 AM
It's not that it "prints a blank space", rather it's that "c" keeps incrementing and resetting regardless as to whether anything was printed.

It sounds like you only want to increase "c" if #a > 0.
Thanks that fixed it :D/>