ComputerCraft Help Please!

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

Captain Caleb

New Member
Jul 29, 2019
5
0
0
I'm using FTB Infinity and I'm attempting to use the OpenPeripheralsAddons block, the Sensor. However, after wrapped the peripheral, It seems I can't get an output from getPlayers(). I'm unaware how to paste my code into a copy-paste box, so I'll type it out like normal.

s = peripheral.wrap("back")
s.getPlayers()

One anomaly is that when I go into the interactive Lua program built in to the computer, is that the same code works.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
Never used the sensor but I think this will print every player
Code:
--wrap the peripheral local to make it a local variable
local s = peripheral.wrap("back")
--get a table which I think contain will contain all the players
local players= s.getPlayers()
--loop over the table
for players in pairs(key,value)do
--print the keys and the values of the table
print(key,value)
end
if it does not print the players you at least see what is stored.
 

Captain Caleb

New Member
Jul 29, 2019
5
0
0
Giving me a bios error: test:3: bad argument: table expected, got nil. If I could be more clear, I'd like the sensor to tell me who is in my chamber, so I could have it print the username of the player in the chamber.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
You removed the lines that started with -- I suppose.
where you in the range of the sensor?

edit to clarify what happens (if you removed the lines that started with --)
for some reason the sensor gives nil. I taught it would give a table with player names but as I already said I never used it and I can't test it right now.
 

Captain Caleb

New Member
Jul 29, 2019
5
0
0
I typed out the code myself, so I removed the lines, and tried it again with the lines. I was in range of the sensor. Something to note, getPlayers() gives the UUID and the name. When I attempt to print(name) it prints a blank space.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
what happens if you do:

s = peripheral.wrap("back")
print(s.getPlayers())
 

ljfa

New Member
Jul 29, 2019
2,761
-46
0
I think the loop has to look like this:
Code:
for key, value in pairs(s.getPlayers()) do
    print(key, value)
end
That should print out the table entries.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
I think the loop has to look like this:
Code:
for key, value in pairs(s.getPlayers()) do
    print(key, value)
end
That should print out the table entries.
And I know see the derp I made, thats what I get when I write code when I am distracted

@Captain Caleb sorry for derping and wasting your time the above is correct