This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
themooser's profile picture

Trying to make a SIMPLE Redstone In Motion API [NEED HELP!]

Started by themooser, 10 January 2014 - 05:12 PM
themooser #1
Posted 10 January 2014 - 06:12 PM
Ok, so I'm kinda new to LUA, though, I know Java.
The error I get is that :21: is giving me a nil value.


local motorSide = "right"
function info()
-- For directions, 0 is down, 1 is up, 2 is north (-Z), 3 is south (+Z), 4 is west (-X), and 5 is east (+X).
-- For the simulation flag, true is simulate (don't actually move anything) and false is don't simulate (actually move the carriage).
-- For the anchoring flag, true is the controller will stay where it is, and false is move the controller with the carriage.
-- If the command is not issued with correct syntax, or
-- if the carriage is somehow obstructed or malformed, an error1 will be printed;
-- If the carriage is not configured properly, the return code will be "false" and a plain-English error1 message;
-- If the carriage is obstructed, the return code will be "false", a plain-English error1 message, and the X/Y/Z coordinates of the obstruction;
-- Otherwise, the return code will be "true".

--drive=peripheral.wrap("left")
--drive.move(3,false,true)

--peripheral.call(motorSide,"move",2,false,false)
end

function north()
	p=peripheral.wrap(motorSide)
	peripheral.call(motorSide,"move",2,false,false)
	--2
	--drive.move(2,false,false)
end

function east()
	p=peripheral.wrap(motorSide)
	peripheral.call(motorSide,"move",5,false,false)
	--5
	--drive.move(5,false,false)
end

function south()
	p=peripheral.wrap(motorSide)
	peripheral.call(motorSide,"move",3,false,false)
	--3
	--drive.move(3,false,false)
end

function west()
	p=peripheral.wrap(motorSide)
	peripheral.call(motorSide,"move",4,false,false)
	--4
	--drive.move(4,false,false)
end

function down()
	p=peripheral.wrap(motorSide)
	peripheral.call(motorSide,"move",0,false,false)
	--0
	--drive.move(5,false,false)
end

function up()
	p=peripheral.wrap(motorSide)
	peripheral.call(motorSide,"move",1,false,false)
	--1
	--drive.move(6,false,false)
end
Edited by
Alice #2
Posted 10 January 2014 - 08:39 PM
I don't know much about Redstone in Motion, but there are a few things I noticed off the bat.
When wrapping a peripheral, you don't need to use peripheral.call, I think
p = peripheral.wrap(side) p.write("Hi")
is the same as
peripheral.call(side, "write", "Hi")
You messed up, I think, when you used peripheral.call(side, method, arg1, arg2), because the arguments I think also have to be in a string.
You also could use p.method(arg1, arg2).
I can't fix the code right now, but for anyone else who can help you this should help both you and them.
CometWolf #3
Posted 10 January 2014 - 09:04 PM
The arguments for peripheral.call can be any data type, however side and method need to be a string.

p=peripheral.wrap(motorSide) -- this however, like Death pointed out, is redundant since you don't appear to be using p.
peripheral.call(motorSide,"move",2,false,false)
Anyways, from what i can make out line 21 is

--2
You sure you posted the right code? And the error code includes your own program name, and not peripheral, correct?
Edited on 10 January 2014 - 08:05 PM
themooser #4
Posted 11 January 2014 - 02:01 PM
I don't know much about Redstone in Motion, but there are a few things I noticed off the bat.
When wrapping a peripheral, you don't need to use peripheral.call, I think
p = peripheral.wrap(side) p.write("Hi")
is the same as
peripheral.call(side, "write", "Hi")
You messed up, I think, when you used peripheral.call(side, method, arg1, arg2), because the arguments I think also have to be in a string.
You also could use p.method(arg1, arg2).
I can't fix the code right now, but for anyone else who can help you this should help both you and them.
The arguments for peripheral.call can be any data type, however side and method need to be a string.

p=peripheral.wrap(motorSide) -- this however, like Death pointed out, is redundant since you don't appear to be using p.
peripheral.call(motorSide,"move",2,false,false)
Anyways, from what i can make out line 21 is

--2
You sure you posted the right code? And the error code includes your own program name, and not peripheral, correct?

This is the new code.. Don't seem to work, but atleast it's the current one..

local motorSide = "right"
function info()
– For directions, 0 is down, 1 is up, 2 is north (-Z), 3 is south (+Z), 4 is west (-X), and 5 is east (+X).
– For the simulation flag, true is simulate (don't actually move anything) and false is don't simulate (actually move the carriage).
– For the anchoring flag, true is the controller will stay where it is, and false is move the controller with the carriage.
– If the command is not issued with correct syntax, or
– if the carriage is somehow obstructed or malformed, an error1 will be printed;
– If the carriage is not configured properly, the return code will be "false" and a plain-English error1 message;
– If the carriage is obstructed, the return code will be "false", a plain-English error1 message, and the X/Y/Z coordinates of the obstruction;
– Otherwise, the return code will be "true".

–p=peripheral.wrap("left")
–p.move(3,false,true)

–peripheral.call(motorSide,"move",2,false,false)
end

function north()
p=peripheral.wrap(motorSide)
–p.call(motorSide,"move",2,false,false)
–2
p.move(2,false,false)
end

function east()
p=peripheral.wrap(motorSide)
–p.call(motorSide,"move",5,false,false)
–5
p.move(5,false,false)
end

function south()
p=peripheral.wrap(motorSide)
–p.call(motorSide,"move",3,false,false)
–3
p.move(3,false,false)
end

function west()
p=peripheral.wrap(motorSide)
–p.call(motorSide,"move",4,false,false)
–4
p.move(4,false,false)
end

function down()
p=peripheral.wrap(motorSide)
–p.call(motorSide,"move",0,false,false)
–0
p.move(5,false,false)
end

function up()
p=peripheral.wrap(motorSide)
–p.call(motorSide,"move",1,false,false)
–1
p.move(6,false,false)
end


When I do cm.north() I get a nil at 21; witch is –2, but it is the code below it that don't work atm "p.move(2,false,false)"
Any suggestions?
Luminite2 #5
Posted 23 April 2014 - 03:32 PM
If p.move is giving you a nil, that means that p is nil (i.e. it isn't getting wrapped properly). Ensure that the motor is on the correct side and that it is the right kind (carriage controller). If that doesn't identify the problem, ensure that you have CC 1.58; RIM could have trouble if the version isn't correct. Also, as a side note, check out Remain in Motion, a more up-to-date fork of this mod; I can confirm that it works wonderfully with CC 1.6x.
Edited on 23 April 2014 - 03:14 PM