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

from table to string

Started by luckie12, 22 May 2015 - 10:57 PM
luckie12 #1
Posted 23 May 2015 - 12:57 AM
Hi everybody!

Im trying to make a sensor to display all the people closeby,
But the problem i have is; Everytime i run the code it says

Table: $$$$$$

This is my code;

mon.peripheral.wrap("left")
print(mon.getPlayers())

But that only shows the table and a random serie of numbers.

Can somebody explain me what i have to do to get it right?
And maybe expand the range? THankyou :D/>
Thankyou!

Kind regards,

Luc
Edited on 22 May 2015 - 11:06 PM
Bomb Bloke #2
Posted 23 May 2015 - 01:31 AM
You don't want to print the table, you want to print what's IN the table. If you're not sure what's in there, then one method is to use the pairs iterator function to get the index names and their assigned values.

Per this tutorial, a suitable loop would be:

for key,value in pairs(mon.getPlayers()) do print(key,value) end
luckie12 #3
Posted 23 May 2015 - 11:38 AM
I get this;



Test:2: Attempt to inex ? (a number value)

Line 2:

do print(key,value)
Anavrins #4
Posted 23 May 2015 - 06:03 PM
I get this;



Test:2: Attempt to inex ? (a number value)

Line 2:

do print(key,value)
Try print(tostring(key), tostring(value))
luckie12 #5
Posted 23 May 2015 - 06:11 PM
i have this now


radarr = peripheral.wrap("left")
while true do
a = textutils.serialize radarr.getPlayers())
do print(a)
sleep(1.75)
end
end

That shows me on the monitor:


{
    {
	   uuid = "################################"
	   name= "Myname"
    },
}

I just want the name

I get this;



Test:2: Attempt to inex ? (a number value)

Line 2:

do print(key,value)
Try print(tostring(key), tostring(value))

Still shows me only the table
KingofGamesYami #6
Posted 23 May 2015 - 07:27 PM

radarr = peripheral.wrap("left")
while true do
  a = radarr.getPlayers()
  for k, v in pairs( a ) do --#iterate through 'a', k bein a key, v being the value of a[k]
    print( v.name ) --#prints the value of a[k].name
  end
  sleep(1.75)
end
luckie12 #7
Posted 23 May 2015 - 07:32 PM
That works! Can you also expend the range of a sensor?

Thanks!
KingofGamesYami #8
Posted 23 May 2015 - 07:35 PM
I'd have no clue on expanding the range of the sensor - I'm not even sure what mod you are using. If I had to guess, I'd say modifying the mods' config file would work.
luckie12 #9
Posted 23 May 2015 - 07:48 PM
Oh well, that would be no option modifying it haha, its an actual multiplayer server owned by others :P/>
Bomb Bloke #10
Posted 24 May 2015 - 12:25 AM
Depending on the sensor, you might be able to increase the range by crafting it together with a turtle, then having that run your script. IIRC, the OpenPeripherals sensor has a range of something like 10 blocks, but gains another 20 when used by a turtle.
luckie12 #11
Posted 24 May 2015 - 06:55 PM
Oh, i didnt know that :D/> thanks :D/>