Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
PHOBOSS98

HELP my drone fainted

Question

so for context I tested this code on some bots:

local component = require("component")
local event = require("event")
local robot = require("robot")
component.modem.open(1)

local function b(_,_,_,_,_,mov)
    if mov=="follow" then
        for k,v in pairs(component.radar.getEntities()) do
            if v.name=="PHOBOSS" then

                    if v.y<-1 then
                        for i=0,v.y,-1 do robot.down() end
                    end
                    if v.y>-1 then
                        for i=0,v.y, 1 do robot.up() end
                    end
                    if v.y==-1 then
                        print("level") --just for %!@$ and giggles
                    end
            end
        end
    end
end

event.listen("modem_message", b)

with the radar upgrade installed I made them track my movement and told them to follow me moving up and down ( I just did this to test out my code)

it worked as long as you keep broadcasting "follow"

now I tried implementing this to a drone (cause its cool and way easier to set its movements):

 

local d= component.proxy(component.list("drone")())
local m= component.proxy(component.list("modem")())
local r= component.proxy(component.list("radar")())
m.open(1)

when true do
local_,_,_,_,_,rtable,mov,x,y,z = computer.pullSignal()
    if mov=="follow" then
        for k, v in pairs(r.getEntities()) do   - - # for clarification, here's an example: r.getEntities() = { {distance=3.008877656445322,name="PHOBOSS",x=7,z=0,y=0} , {name="Chicken",distance=5.7886764534321234,z=5,y=3,x=-2}... } 
            if v.name=="PHOBOSS" then
                d.move(v.x,v.y,v.z)
            end
        end
    end
end

 

but the moment that it would read:

for k, v in pairs(r.getEntities()) do
            if v.name=="PHOBOSS" then
                d.move(v.x,v.y,v.z)

the drone shuts off...

pls holp XD

Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Debugging drones can be difficult but the analyzer will help you get an error message from crashed programs on microcontrollers. Seeing the code and where you say it crashes.. I'd say that indexing the supposed table `v` caused the error. Indexing being `v.name` or `v.x`. I suppose if v.x or v.z or v.y are nil then drone.move will likely throw an error. But it's hard to know without more info. Get that analyzer data and come back.

Hell, just wrap the whole code in pcall and collect any errors.

local d= component.proxy(component.list("drone")())
local m= component.proxy(component.list("modem")())
local r= component.proxy(component.list("radar")())
m.open(1)

local ok, err --# declare outside loop so we can get the value later

when true do
local rtable,mov,x,y,z = select(6, computer.pullSignal())
    if mov == "follow" then
    	ok, err = pcall(function()
            for k, v in pairs(r.getEntities()) do
                if v.name == "PHOBOSS" then
                    d.move(v.x, v.y, v.z)
                end
            end
        end) --# pcall end
    
        if not ok then --# we have an error
      	    break --# break the while loop
        end
    end
end
-- # send the error back to our controller and finish
m.send(ourHost, port, 'ERROR: '..(err or ""))

 

Link to post
Share on other sites
  • 0

what, do I just smack the drone with it?:

 

 

 

I don' think that the radar would give out a nil value I tried broadcasting the 'v' entries from the drone with this code:

 

local d= component.proxy(component.list("drone")())
local m= component.proxy(component.list("modem")())
local r= component.proxy(component.list("radar")())
m.open(1)

while true do
local_,_,_,_,_,rtable,mov,x,y,z = computer.pullSignal()
    if mov=="follow" then
        for k, v in pairs(r.getEntities()) do
            m.broadcast(1,v.name,v.distance,v.x,v.y,v.z)
        end
    end
end

 

I got this in return:

 

...before the drone fainted

again

Link to post
Share on other sites
  • 0

well thats odd... apparently the drone tries to broadcast twice, I tweaked the code a small bit:

 

local computer=require("computer")
local component=require("component")

local d= component.proxy(component.list("drone")())
local m= component.proxy(component.list("modem")())
local r= component.proxy(component.list("radar")())
m.open(1)

while true do
local_,_,_,_,_,rtable,mov,x,y,z = computer.pullSignal()
    if mov=="follow" then
        for k, v in pairs(r.getEntities()) do
            m.broadcast(1,"rreeeee") - - #Le tweak
        end
    end
end

 

and then got this:
adsfasfsdfssdffsdsfdasf.thumb.png.41351a5748233005cb15834199676f93.png

but when it tries to broadcast the 'v' entries it does this:

coordinate.thumb.png.f700b202fb5536282f79d7b4fe601866.png

then shuts down...

maybe thats what's causing it to crash?(I'm just guessing here)... it doesn't happen outside the "for k,v in pairs()..." line:

 

local computer=require("computer")
local component=require("component")

local d= component.proxy(component.list("drone")())
local m= component.proxy(component.list("modem")())
local r= component.proxy(component.list("radar")())
m.open(1)

while true do
local_,_,_,_,_,rtable,mov,x,y,z = computer.pullSignal()
    if mov=="follow" then
        m.broadcast(1,"skrrrrra") - - #does it once
        for k, v in pairs(r.getEntities()) do
            m.broadcast(1,"ka") - - #does it twice
        end
        m.broadcast(1,"pa pa ka") - -#does it once
    end
end

 

see:

kaka.thumb.png.a301fbdf05dc56e07a0cd048216fde4c.png

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.