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

Need help whit robot movement

Question

1 answer to this question

Recommended Posts

  • 0

Hi, what's nice is that robot.forward, etc return a value.  Learn more about the function returns on this wiki page http://ocdoc.cil.li/api:robot So all we need to do is check its return value as being true or nil. When it's nil, then it returns a reason why it's failed. In the code below I included two possible reasons it could have failed, and you can add what you want it to do yourself.  Hope it helps you, also try having it either be on pastebin/github or just written in the post details so that we don't need to download sketchy internet files.  Wish I knew how to put the code in the spoiler thing.  :/

local os = require("os")
local component = require("component")
local robot = require("robot")
local computer = require("computer")
local shell = ("shell")

function up(a)
	while a >= 1 do
	local result, possibleError = robot.up()
		if result == true then
			a = a - 1
		else
		print(possibleError)
			if possibleError == "solid"
			
			elseif possibleError == "entity"
		
			else
			
			end
		end
	end
end

function forward(a)
	while a >= 1 do
	local result, possibleError = robot.forward()
		if result == true then
			a = a -1
		else
			print(possibleError)
			if possibleError == "solid"
			
			elseif possibleError == "entity"
		
			else
			
			end
		end
	end
end

function back(a)
	while a >= 1 do
	local result, possibleError = robot.back()
		if result == true then
		a = a - 1
		else
			print(possibleError)
			if possibleError == "solid"
			
			elseif possibleError == "entity"
		
			else
			
			end
		end
	end
end

function down(a)
	while a >= 1 do
	local result, possibleError = robot.down()
		if result == true then
		a = a - 1
		else
			print(possibleError)
			if possibleError == "solid"
			
			elseif possibleError == "entity"
		
			else
			
			end
		end
	end
end

function sleep(a)
	os.sleep(a)
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.