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

Computer not fast enough?

Started by gheotic, 08 November 2015 - 03:25 AM
gheotic #1
Posted 08 November 2015 - 04:25 AM
I'm trying to make the sensor from openPeripheral detect when players are walking above it, and it all works very well. Except if they move too fast. First it looks for players, then it takes the first playerName in the table and use it in a command to get more information about that one player. The problem is that the computer isn't fast enough to get players nearby and get further information before that player is gone. So it throw this error:

startup:5: Entity not found


p = peripheral.wrap("bottom")
while true do
   local players = p.getPlayers()
   if players ~= nil and players[1] ~= nil then
	  playerName = players[1]["name"]
	  player  = p.getPlayerByName(playerName) -- Error occur here
   end
   os.sleep(0.5)
end
  
Creator #2
Posted 08 November 2015 - 08:22 AM
You could add a check like ifPlayerisPresent. If he still is the do the other check. I'm not sure this is the name of the method so look it up.
gheotic #3
Posted 08 November 2015 - 11:39 AM
I don't think there is a command called that?
Creator #4
Posted 08 November 2015 - 11:41 AM
Maybe something similar. I am not sure, it was only a suggestion that might or might not work.
Bomb Bloke #5
Posted 08 November 2015 - 12:24 PM
At least when I last tried it, the OpenPeripheral sensor had a "getPlayerNames" function and a "getPlayerData" function. Or was it the CCSensors one? OpenCCSensors? Hard to tell, can't remember, and I gather the former has been known to interfere with the latter(s). In any case, the first function gives a list of players, and the second - if passed a player name - either returns the desired data, or if the player isn't in range, nil. As opposed to generating an error, which seems silly.

If you're not seeing such an alternative, then you could always pcall "getPlayerByName":

local ok, player = pcall( p.getPlayerByName, playerName )

if ok then
  -- do stuff with "player"
end
Edited on 08 November 2015 - 11:27 AM
Lyqyd #6
Posted 08 November 2015 - 07:04 PM
Yeah, those calls are part of OpenP. OCS uses getTargets and getTargetDetails, on all of the various sensor types.
gheotic #7
Posted 09 November 2015 - 08:40 AM
Well that sound like a good solution for my problems :D/> Now it would be nice to get pass this school day, so i can get home to test it out!