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

Sensor Monitor (OpenPeripheral)

Started by dxtrxc23, 27 December 2015 - 09:32 PM
dxtrxc23 #1
Posted 27 December 2015 - 10:32 PM
helo community, hello @Bomb Bloke
basicly i cant figure out how to get his programs woking: http://pastebin.com/5QSq59RT for the "server" and http://pastebin.com/7pbWTBjw for the turtle
as in previous topics discussed users have a problem within line 19 of the server script + igot some more question to this program(how can it maxed out etc.)
so as in one thread explained he told one users how to get rid of the error in line 19 of the server script. but if i place then minimum amount of monitors next to the "server" computer it gives me an error: attempt to index? (a nil value).itried but i cant figure it out how to solve this.
and now some more questions: as everybody knows you need to change the co-ordinates to fit to your "settings".
so for what is

local sensorPos, mon, roomSensor, hunting = {-332,76,-841}, {}
[color=#66CC66][font=Consolas, Menlo, Monaco,][color=#222222]
hunting and its co-ordinates standing for? the sensor position? and do i need to connect the openperipherals sensor via a periheral proxy or is the cc computer detcting the sensor without that?
door pos is ez :)/>

local bounds = {{-349,-321},{78,84},{-864,-817}}
is this the area of the sensor the turtle is patrouling in? what do i need to change here that it would fit; like the preset for the sensor is the radius 5 but you can change that in config.

last question: i need to use a wireless turtle with a sword in one of the slots right?
im sorry if those are nooob questions but it seems like i found much potential in this program and would love to get it running/working. it should be pretty op on servers ;)/>
i appreciate all of your help guys, thnaks in advantage!!
best regards

p.s is it hard to add a "mob" function e.g to make it work with players and mobs?
Dragon53535 #2
Posted 27 December 2015 - 10:53 PM
Probably not difficult for the mod thing. That attempt to index a nil value, can you give the full error for that?

The hunting line you're talking about

local sensorPos, mon, roomSensor, hunting = {-332,76,-841}, {}
roomSensor and hunting are both nil, sensorPos gets that first table ({-332,76,-841}) and that's your sensors coordinates. If you need that, just basically stand on the sensor and record the coordinates, round up on each though.

The rest, I dunno about, BB patrols the AaP section regularly so he should give a better answer.
dxtrxc23 #3
Posted 27 December 2015 - 11:27 PM
ok i understand, thank you m8
here is the error: startup:19: attemptto index ? (a nil value)
ye i remembered a discussion between you and bomb bloke :)/>
http://www.computercraft.info/forums2/index.php?/topic/20985-an-automated-attack-turtle-with-gps-coordinates/page__p__198525__hl__+sensor%20+monitor__fromsearch__1#entry198525
best regards
Dragon53535 #4
Posted 27 December 2015 - 11:48 PM
Do the edit he said in that post. Change line 19 to this:


for i=1,#mon do mon[i].setTextScale(2) end


Also, I didn't really discus on that post, I just corrected a different person.
Edited on 27 December 2015 - 10:48 PM
Bomb Bloke #5
Posted 28 December 2015 - 08:22 AM
basicly i cant figure out how to get his programs woking: http://pastebin.com/5QSq59RT for the "server" and http://pastebin.com/7pbWTBjw for the turtle

I keep telling people this, but I wrote those with the intention that they'd only be used by myself within one specific base. I've shared them as examples of how one might write their own such scripts, but really my code tends to end up being too verbose to make a good example of, well, anything really. The best way to explain them would be for me to make a "let's write these from scratch" video or something.

so for what is

local sensorPos, mon, roomSensor, hunting = {-332,76,-841}, {}
hunting and its co-ordinates standing for? the sensor position?

Dragon's pointed this out, but here I'm setting sensorPos to {-332,76,-841}, mon to {}, and roomSensor and hunting are remaining undefined (they're simply being declared as local to the script, ready for later use). See this guide regarding assignments for more on how multiple variables/values in a single line works.

roomSensor later ends up being assigned the wrapped sensor peripheral (in the loop immediately below), and hunting gets used to track the name of the player the turtles should be chasing (staying as nil whenever there's no one to chase).

and do i need to connect the openperipherals sensor via a periheral proxy or is the cc computer detcting the sensor without that?

It doesn't really matter so long as it's connected. I think I used a proxy and some networking cable so I could stick it in the middle of my particular base.


local bounds = {{-349,-321},{78,84},{-864,-817}}
is this the area of the sensor the turtle is patrouling in?

Yes, in a {{x1,x2},{y1,y2},{z1,z2}} format. Basically anything the sensor picks up, but is determined to be outside of these bounds, gets ignored as being "outside the base".

last question: i need to use a wireless turtle with a sword in one of the slots right?

Yes.

p.s is it hard to add a "mob" function e.g to make it work with players and mobs?

That depends on your ability to figure out how to get the sensor to tell you where mobs are.

Mostly the whole thing where the server computer tells the turtles to "chase playername!" is cosmetic (so I could click on a turtle and see what it thought it was doing); the important bit is where it says "go to this location!". The turtles keep swinging their swords where ever they go, so if the server keeps pointing them to a spot where mobs are, then the mobs get killed.
dxtrxc23 #6
Posted 28 December 2015 - 10:45 AM
thank you for your post, all well printed out.
but i ran into another error:
startup:43: attempt to index ? (a nil value)
i ve changed the co-ordinates and the mon.
http://pastebin.com/NxPHXVzv
best regards
Bomb Bloke #7
Posted 28 December 2015 - 01:52 PM
The error is telling you that you're attempting to treat a variable as a table pointer, when it's actually undefined. "roomSensor" is the only one you're indexing into on that line, so that means the conditional on line 12 never found a peripheral with the type "openperipheral_sensor_1".

Note that peripheral names are not the same as their types. The original code simply wrapped the first sensor it found, regardless as to what it was called. If you really want to wrap a specific sensor with a specific name, then delete lines 12 and 13, and change line 3 to:

local sensorPos, mon, roomSensor, hunting = {-211,68,-89}, {}, peripheral.wrap("openperipheral_sensor_1")
dxtrxc23 #8
Posted 28 December 2015 - 04:17 PM
:/
so i ran this modified program : http://pastebin.com/xESifaum to see if i am in the radius and to set my "bounds"
changed all the things u said, still getting error. startup:41: attempt to index ? (a nil value)
i think it has something to do with the getPlayerNames; so i listed all aviable functions: the only function i can call for players is getPlayera() etc. here a screenshot:
another thin to mention: i tried connceting a sensor via modem and networking cable. then i searched for peripherlas and i only get modem. so it cant find the sensor. same thing via peripheral proxy too.
so i tried it with getPlayers() still error.
dunno what to do
so far this is what we got: http://pastebin.com/9ipC0izX
Dragon53535 #9
Posted 28 December 2015 - 07:27 PM
so far this is what we got: http://pastebin.com/9ipC0izX


local sensorPos, mon, roomSensor, hunting = {-322,65,-160}, {}, peripheral.wrap("openperipheral_sensor")

This line is still wrong…

If your sensor is attached by way of wired modems, then right click on the modem until it's got the red ring (If it already has it, do it again), in your chat you should see something like "openperipheral_sensor_x connected" whatever it says, change that bit inside the peripheral.wrap to. So if it says "openperipheral_sensor_53 connected" then you would change that line to this:

local sensorPos, mon, roomSensor, hunting = {-322,65,-160}, {}, peripheral.wrap("openperipheral_sensor_53")

If your sensor is attached on one of the sides of the computer, then change the peripheral.wrap to that side


local sensorPos, mon, roomSensor, hunting = {-322,65,-160}, {}, peripheral.wrap("left")
Sides are from looking at the screen: left, right, front, back, top, bottom
dxtrxc23 #10
Posted 28 December 2015 - 07:59 PM
lol how could i forget that? my bad.
next error pops up:startup:45: attempt to call nil
Bomb Bloke #11
Posted 29 December 2015 - 12:15 AM
You're attempting to call a function that doesn't exist. If line 45's still this one:

        local pData = roomSensor.getPlayerData(players[i])

… then whatever sensor you wrapped does not have a "getPlayerData" function available to it.
dxtrxc23 #12
Posted 29 December 2015 - 01:25 AM
Hmhh, then the function got removed from openperipherals sensor. Tried some methods programs where i get all methods aviable for the peripheral. The function getPlayerData is not displayed..
Does anybody know a different/Same function for getPalyerData. So far what seems familiar is getEntityData. But then is a error displayed saying something about uuid.
HPWebcamAble #13
Posted 29 December 2015 - 02:46 AM
Hmhh, then the function got removed from openperipherals sensor. Tried some methods programs where i get all methods aviable for the peripheral. The function getPlayerData is not displayed..
Does anybody know a different/Same function for getPalyerData. So far what seems familiar is getEntityData. But then is a error displayed saying something about uuid.

What functions DOES the sensor have? You can use my Get Methods program if it has too many functions to display on one page: http://pastebin.com/sKLqTGrM

I'm guessing the thing about a UUID means you have to pass the function a UUID and it returns info about that entity (could be a player or a mob). Some other function must give you a list of all the entities and their UUID's
Edited on 29 December 2015 - 01:47 AM
dxtrxc23 #14
Posted 29 December 2015 - 10:30 AM
i have excatly used your porgram; man i wanted to thank you before :)/> gj with that
here are all methods aviable: http://www.directupload.net/file/d/4217/4vqcnlrn_png.htm
i ve tried it with the getEntityData but it gives me an error: http://www.directupload.net/file/d/4217/cp8g5lz5_png.htm
Bomb Bloke #15
Posted 29 December 2015 - 11:15 AM
I'd wager you just want to swap "getPlayerData" with "getPlayerByName". I'm not entirely sure the results returned will be in the same format, but I seem to remember it should be pretty close.
dxtrxc23 #16
Posted 29 December 2015 - 12:00 PM
errors over erros: startup:45: Entity not found
well it seem that we are searching for an entity but not for his details xD
Bomb Bloke #17
Posted 29 December 2015 - 12:22 PM
Get the script to print out what the entity you've got it looking for is (the value of players), go read the documentation for the sensor's functions (apemanzilla's script may help you with that), and adjust accordingly.
dxtrxc23 #18
Posted 29 December 2015 - 01:13 PM
so ye made a lil program: http://pastebin.com/eJ4ExZGw
it gives me no error :)/> if i stand inside the sensor radius; as soon as i go outside the area; error coming up. tester:5: Entity not found
and no information is dispaly on the monitor

edit: but i think after running opduc the function getPlayerbyName should be right, i just havent figured out what the function gives us: like details for the play and how you can fin them out.
Edited on 29 December 2015 - 12:15 PM
Bomb Bloke #19
Posted 29 December 2015 - 01:25 PM
It's not entirely practical to check that a player is in range before you scan them, because function calls take time and players can move while code executes; whoever coded that in as a requirement mustn't've thought too hard about what they were doing. To put it politely.

I suppose that you could pcall getPlayerByName. I believe the last one to run into a build of OpenPeripheral with this behaviour was able to do so, anyway:

success, players = pcall( prox.getPlayerByName, "jetski67890" )

You'll need to check that "success" is true before you attempt to get the length of "players" (as if the command errored then "players" will end up as nil, which you obviously can't get the length of).
dxtrxc23 #20
Posted 29 December 2015 - 01:35 PM
ah i cant follow you, how can i implement that i you code/ the tester
edit: can somebody explain me/ better implement this
Edited on 29 December 2015 - 08:36 PM
Bomb Bloke #21
Posted 30 December 2015 - 08:51 AM
Your tester currently polls the sensor, then attempts to loop through the results. It crashes if the sensor can't find the specified player.

I'm saying to pcall the sensor's function (so that the script keeps running even if OpenPeripheral tries to error), but wrap an if/then block around your loop to prevent that from running if there were no results to iterate through. "if success then (do the loop) end".
dxtrxc23 #22
Posted 30 December 2015 - 10:16 AM
ye got it, program is running but still showing me nothing: its becasue of mon.write("i can put something in here still no error, but nothing show up"), how can i find out what the result of the getPlayersByName is? i used opdoc: its gtePlayersByName(username) argument: username returns object
http://pastebin.com/tyufjrSq
Bomb Bloke #23
Posted 30 December 2015 - 10:37 AM
If you're using ComputerCraft 1.74 specifically, you may need to tweak the top of your script like this to get the monitor to work:

mon = peripheral.wrap("left")
mon.setTextScale(0.5)
mon.setTextScale(1)

I suspect your "if #players ~= 0 then" check might have something to do with it, though. "players" will only be more than 0 if it has numeric indexes in it. If it only contains string-based keys, you'll get nothing that way.

Try:

term.clear()
term.setCursorPos(1,1)

if success and type(players) == "table" then
 print("detected this stuff:")
 for a,b in pairs(players) do
   print(tostring(a) .. ": " .. tostring(b))
 end
else print("detection failure") end

This way you should get some output no matter what.
Edited on 30 December 2015 - 11:29 AM
dxtrxc23 #24
Posted 30 December 2015 - 10:43 AM
bios:14: [string "tester"]:14: unexpected symbol
http://pastebin.com/nLyygrsr
Bomb Bloke #25
Posted 30 December 2015 - 12:30 PM
Grr. If you see a "B)/>" in someone's post, they usually mean "b)" - bug in this version of the forum software related to emoticons. Switch it over and give it another go.
Edited on 30 December 2015 - 11:30 AM
dxtrxc23 #26
Posted 30 December 2015 - 02:03 PM
nice! got now some tables for various things: http://www.directupload.net/file/d/4218/2hvfzi84_png.htm and http://www.directupload.net/file/d/4218/rh49254r_png.htm
this is now the tester program: http://pastebin.com/qpe223eK
but we are still working on this :P/> http://pastebin.com/PDUKhQbq
i changed players to username because its getPlayerByName(username)
still getting error startup:45: attempt to index ? (a nil value)
HPWebcamAble #27
Posted 30 December 2015 - 06:16 PM
i changed players to username because its getPlayerByName(username)
still getting error startup:45: attempt to index ? (a nil value)

getPlayersByName( username ) means it wants a username. It's just to let anyone using it know what the function is looking for.

The variable name YOU use (in this case, players) doesn't matter. That function only cares about the VALUE the variable holds.
Try changing it back to
players[i]
Edited on 30 December 2015 - 05:16 PM