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

What's the best way tell a drone to pause in a sequence of movements?

Question

Im trying to get my drone to pause for a moment after it moves but it seems the drone reads the code too fast and instead just jutters like as if it was nodding... what's the shortest piece of code (thats compatible for both mac and windows) can you put in the sequence to tell it to pause for a second or two? here's my code:

  1. local r=component.proxy(component.list("radar")())
  2. local m=component.proxy(component.list("modem")())
  3. local d=component.proxy(component.list("drone")())
  4. d.setLightColor(0x00FFD8)
  5. m.open(001)
  6. while true do
  7.     local evt_,_,_,_,name,cmd,x,y,z = computer.pullSignal()
  8.         if evt=="modem_message" then
  9.             if cmd=="test z" then
  10.             d.move(0,3,0)
  11.             d.move(0,-3,0)
  12.             end
  13.             if cmd=="test x" then
  14.             d.move(3,0,0)
  15.             d.move(-3,0,0)
  16.             end
  17.             if cmd=="shh" then
  18.             break
  19.             end
  20.         end
  21. end
Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

What you want is code that will "block" further execution until some condition is met. Because drone.move is non-blocking(pain in the ass if you ask me :p) we have to write  a function to wait until the drone is finished moving.

function waitUntil(freq, predicate)
  -- # wait 'freq' amount of time until 'predicate' returns true
  repeat computer.pullSignal(freq) until predicate()
end

Can then apply it to your code like so..

local r=component.proxy(component.list("radar")())
local m=component.proxy(component.list("modem")())
local d=component.proxy(component.list("drone")())
d.setLightColor(0x00FFD8)
m.open(001)

function waitUntil(freq, predicate)
  -- # wait 'freq' amount of time until 'predicate' returns true
  repeat computer.pullSignal(freq) until predicate()
end

while true do
    local evt_,_,_,_,name,cmd,x,y,z = computer.pullSignal()
        if evt=="modem_message" then
            if cmd=="test z" then
            d.move(0,3,0)
            waitUntil(0.5, function() return d.getVelocity() == 0 end)
            d.move(0,-3,0)
            end
            if cmd=="test x" then
            d.move(3,0,0)
            waitUntil(0.5, function() return d.getVelocity() == 0 end)
            d.move(-3,0,0)
            end
            if cmd=="shh" then
            break
            end
        end
end

 

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.