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

Keep getting error when running

Question

hi i have a problem i have been trying to figure out for a few days now and i am drawing up a blank. I have to code below  which i have to admit is not my own. 

i have this saved as move.lua

local robot = require('robot')
local component = require('component')

local move = {}

local commands = {}

commands['f'] = robot.forward
commands['b'] = robot.back
commands['u'] = robot.up
commands['d'] = robot.down
commands['tl'] = robot.turnLeft
commands['tr'] = robot.turnRight
commands['ta'] = robot.turnAround
commands['s'] = robot.swing
commands['sd'] = robot.swingDown
commands['su'] = robot.swingUp
commands['p'] = robot.place
commands['pd'] = robot.placeDown
commands['pu'] = robot.placeUp
commands['dr'] = robot.drop
commands['dru'] = robot.dropUp
commands['drd'] = robot.dropDown
commands['su'] = robot.suck
commands['sud'] = robot.suckDown
commands['suu'] = robot.suckUp
commands['us'] = robot.use
commands['usu'] = robot.useUp
commands['usd'] = robot.useDown

--if component.piston then
--	commands['p']=component.piston.push
--end
--if component.inventory_controller then
--	commands['e']=component.inventory_controller.equip
--end
function move.act(act)
	local status, reason, c
	c = commands[act]
	if c then
		status, reason = c()
		return
	else
		print("Not found" .. act)
	end
	if not status then
	
	end
end
function move.move(path)
	--path = ('f2,r,f1,b') 
	for word in string.gmatch(path, '([^,]+)') do
		local num = string.match(word, '%d+') or 1
		local word = string.match(word, '[^%d]+')
		for i=1,num do
			move.act(word)
		end
	end
end

if i pass the instructions to move the robot at the end of this script then it moves but when i try passing instructions to move the robot via a different script like below then i get an error 

attempt to index a local 'move' ( a nil value)

the code i am using to pass the information is this 

local move = require("move")

for i=1,10 do
	move.move('f')
end

move.move('b10')

anybody got any ideas.

thanks in advance

Link to post
Share on other sites

2 answers to this question

Recommended Posts

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.