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

Modem Utility help!

Started by PyroGodz, 01 October 2012 - 12:00 AM
PyroGodz #1
Posted 01 October 2012 - 02:00 AM
Hey guys, since I'n planning on doing alot of networking, I've decided to write on a floppy disk an entire Modem Utility program.
Currently I'm doing the selections for opening a modem. Afterwards, I will be creating one to close modems. This program is the startup for the disk.

term.clear()
term.setCursorPos(1,1)

write("Welcome to RedNet modem startup utility!")

term.setCursorPos(1,3)

write("Which side is your modem on?")

term.setCursorPos(1,4)

print("L = Left")

print("R = Right")

print("F = Front")

print("B = Back")

print("BT = Bottom")

print("T = Top")

term.setCursorPos(1,10)

write("Side: ")

local input = read

if input == "L" then

rednet.open(left)

elseif input == "R" then

rednet.open(right)

elseif input == "F" then

rednet.open(front)

elseif input == "B" then

rednet.open(back)

elseif input == "BT" then

rednet.open(bottom)

elseif input == "T" then

rednet.open(top)

else

term.setCursorPos(1,11)

print("That letter does not correspond to a side!")

sleep(3)

os.reboot()

end      

It seems that when I start this up from a disk, or from anything for that matter, everything shows up, including "That letter does not correspond to a side!" It also keeps flashing, indicating that it's rebooting. I'm not sure why it would be doing this if I haven't input anything yet. Help appreciated, thanks!
Lyqyd #2
Posted 01 October 2012 - 02:03 AM
You're not calling read(). You need the parentheses.
PyroGodz #3
Posted 01 October 2012 - 02:09 AM
You're not calling read(). You need the parentheses.

Oh wow, thanks :)/>/> That was stupid of me. Although, now nearly everything works, but when I enter a side, I get the error: rednet:313: string expected
I don't have 313 lines so I'm very confused.. Thanks :(/>/>
Lyqyd #4
Posted 01 October 2012 - 02:10 AM
That's because the variables left, right, etc. are never defined. Try passing strings to rednet.open. Like this:


rednet.open("left")

Notice the quotes.
MysticT #5
Posted 01 October 2012 - 02:11 AM
All the rednet.open calls are missing the quotes on the parameter (front should be "front", back should be "back", etc).

ninja'd :)/>/>
PyroGodz #6
Posted 01 October 2012 - 02:14 AM
That's because the variables left, right, etc. are never defined. Try passing strings to rednet.open. Like this:


rednet.open("left")

Notice the quotes.
All the rednet.open calls are missing the quotes on the parameter (front should be "front", back should be "back", etc).

ninja'd :)/>/>

Oh, thanks to the both of you. Can't believe I made 2 stupid mistakes in 1 program lol.
BrolofTheViking #7
Posted 01 October 2012 - 02:16 AM
Yay! simple fixes!
Though, I'm wondering if, instead of going through all that hassle to write that program, couldn't you just make one that opens every side? would that make any difference?
Orwell #8
Posted 01 October 2012 - 02:59 AM
Yay! simple fixes!
Though, I'm wondering if, instead of going through all that hassle to write that program, couldn't you just make one that opens every side? would that make any difference?

You don't even have to open every side. You could do it like this:

local function openModem()
  for i,side in ipairs(rs.getSides()) do
	if (peripheral.getType(side) == 'modem') then
	  rednet.open(side)
	  return side	-- return the side you opened in case you want to use it after
	end
  end
end
PyroGodz #9
Posted 01 October 2012 - 03:20 AM
Yay! simple fixes!
Though, I'm wondering if, instead of going through all that hassle to write that program, couldn't you just make one that opens every side? would that make any difference?

You don't even have to open every side. You could do it like this:

local function openModem()
  for i,side in ipairs(rs.getSides()) do
	if (peripheral.getType(side) == 'modem') then
	  rednet.open(side)
	  return side	-- return the side you opened in case you want to use it after
	end
  end
end

Although, that does look a lot better, I'm going to stick with mine since I'd like to use something I actually made, thanks though! :)/>/>
Orwell #10
Posted 01 October 2012 - 03:43 AM
Yay! simple fixes!
Though, I'm wondering if, instead of going through all that hassle to write that program, couldn't you just make one that opens every side? would that make any difference?

You don't even have to open every side. You could do it like this:

local function openModem()
  for i,side in ipairs(rs.getSides()) do
	if (peripheral.getType(side) == 'modem') then
	  rednet.open(side)
	  return side	-- return the side you opened in case you want to use it after
	end
  end
end

Although, that does look a lot better, I'm going to stick with mine since I'd like to use something I actually made, thanks though! :)/>/>

I understand that. :(/>/> Though, aside from 'looking better', it also avoids user intervention. Anyways, it's most important that you learn and you don't learn from copying. So you're right. : )
mrSLIMEguy #11
Posted 01 October 2012 - 04:17 AM
Rednet modems cant be placed on the front
Lyqyd #12
Posted 01 October 2012 - 04:29 AM
Sure they can.