Skip to content

Basic Grid Movement Example

This example is here to teach you how you can get your drone to go around your entire map without writing code to tell the drone what to do.


Using for loops allow you to easily create a loop that only repeats the specified amount of time

for i = 1, 3 do
-- function here
end
print("done")

In the script above, the script would repeat 3 times due to it being i being the variable = to 1 and it, by default, adds 1 each time until the value given is met (in our case 3) and then print done when all iterations are complete

Go to Logic & Loops

Pairing this with a simple movement script, you can cover the x axis of your grid

for i = 1, 3 do -- Tip: edit 3 to how long your grid is!
drone.move(Enum.Direction.East)
end

This script will cover your grid, but you might be wondering, this is only one direction; How can you create a loop through all the grid?


To move freely along the x and z axis you can apply another loop to move down when that loop is complete it moves down or up:

for i = 1, 3 do -- Want to form an infinty loop? put `while true do` here
for i = 1, 3 do
drone.move(Enum.Direction.East)
end
drone.move(Enum.Direction.South)
end

The script above will move throughout your field, this happens because during the first loop, it starts the second loop and moves East 3 times and once that is done, it goes past the second loop and moves south, and restarts