Posted 02 January 2015 - 02:47 AM
I'm trying to create a sensor in my base that will do a few things, like turning on a shower if I TP in and am on fire, spit out food if hungry, or potions if injured, that sort of thing.
I created a program that should read player status from the sensor.
I start the program on a computer, and leave the area.
When I return, I will find that the program ends, with a line that say
programname:5: Entity not found
How can I better loop this, so that it'll only run s.getPlayerData("Phantom") when I'm in range, but will keep running even when no entities are in range?
Here is a quick example:
If this has been answered before, I apologize, but I couldn't find any examples quite close enough to help me out using the sensor block. :(/>
Thank you!
**Edited to add code tags… my bad!
***Edited again for clarity.
I created a program that should read player status from the sensor.
I start the program on a computer, and leave the area.
When I return, I will find that the program ends, with a line that say
programname:5: Entity not found
How can I better loop this, so that it'll only run s.getPlayerData("Phantom") when I'm in range, but will keep running even when no entities are in range?
Here is a quick example:
sensor = peripheral.wrap("right")
rs.setoutput("bottom",false)
while true do
local owner = sensor.getPlayerData("Phantom") -- Determine stranger danger or not...
if owner then
local hunger = sensor.getPlayerData("Phantom")["foodLevel"] -- getting hunger level
if hunger < 20 then
-- Code to spit out some food, then sleep for 15
else
rs.setoutput("bottom",false) -- Did this to make sure that my redstone signal returned to false
end
end
sleep(0)
end
If this has been answered before, I apologize, but I couldn't find any examples quite close enough to help me out using the sensor block. :(/>
Thank you!
**Edited to add code tags… my bad!
***Edited again for clarity.
Edited on 02 January 2015 - 03:53 AM