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

Help with reading info from a Table in a Table

Started by Okula, 02 January 2016 - 08:47 PM
Okula #1
Posted 02 January 2016 - 09:47 PM
Hi
Minecraft 1.7.10 Direwold20 Pack

Im currently stuck in programming a OpenP Sensor program that returns the PlayerName to a Monitor.

Im not very skilled in LUA, but i managed to get it to work.. nearly
Because, the info from the Sensor is returning a Table which contains UUID and NAME and i only need teh actual name shown,
but atm it shown both the UUID and the name.

the Table that the Sensor is returning is -> http://pastebin.com/6EsDvnFz

and the program so far is -> http://pastebin.com/WNFmaSLm

I know the rs.output() is not placed the at right place and the "save to file" is only added to look at the info from Sensor.Table:Player

What i want is it to write the Player Name only to the monitor and then activate a redstone signal if detecting anything

Regards
Okula
HPWebcamAble #2
Posted 03 January 2016 - 02:22 AM
You can read more about tables here


In this case, you have a table of tables; each 'sub table' has the UUID and name of a player in range of the sensor.

You can use this code to print each name to a monitor:

local s = peripheral.wrap("side") --# wrap the sensor
local m = peripheral.wrap("side") --# wrap the monitor

local players = s.getPlayers()

if #players > 0 then --# Make sure there is at least 1 player in the table

  m.write( players[ 1 ].name ) --# Write the name of the first player

  for i = 2, #players do
    m.write(", ".. players[ i ].name) --# Write the names of the rest of the players (separated by a comma)
  end

end
Okula #3
Posted 03 January 2016 - 04:12 PM
HPWebcamAble

Thanx alot for the reply, and ty for the help.
I havn't got bundels of time to get into depth with Lua programming so I really appreciate your reply.

Regards Okula