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

Rednet opener! (Super simple!)

Started by stilldabomb, 18 October 2012 - 04:41 AM
stilldabomb #1
Posted 18 October 2012 - 06:41 AM
Rednet opener! (Super simple!)


I will not post a pastebin for this because it is too easy for that.

Don't be a skid.


Code:


for _, side in pairs(redstone.getSides()) do
		rednet.open(side)
end


Thanks to Espen for the redstone.getSides() method that I never noticed
stilldabomb #2
Posted 18 October 2012 - 07:18 AM
Don't go thrashing because it's 3 lines of code. I made it super simple for people that are beginners with LUA.
Espen #3
Posted 18 October 2012 - 11:05 AM
You could also replace your fixed table with the built-in getSides() function of the redstone api to make it both shorter and future-proof:

for _, side in pairs(redstone.getSides()) do
	rednet.open(side)
end

Cheers :P/>/>

P.S.: In case someone learning Lua wonders about the _ (underscore):
In this case I've used it as the variable for the keys which in this case are of no need, because we only need the values ('side' variable).
It's commonly used to denote that either the keys or the values are of no need.
Edited on 18 October 2012 - 09:10 AM
stilldabomb #4
Posted 18 October 2012 - 03:25 PM
Thanks, but it was so it would be compatible for Tekkit cause my friends and I play on it :P/>/>
ChunLing #5
Posted 18 October 2012 - 08:01 PM
Tekkit doesn't have rs.getSides()? Not that I'm super dependent on it or anything, but that's kinda weird.

You also want to make it a function and return true if a modem was opened or false if no modem was found.

local function opnmdm()
for i,v in pairs(rs.getSides()) do
  if peripheral.getType(v) == "modem" then
   if not rednet.isOpen(v) then rednet.open(v) end
  return true end
end
return false end
No, I don't bother to ever use anything other than "for i,v in pairs/ipairs do … end". The i and v both get thrown away at the end of the loop anyway, and it helps me to remember never to set any variables named i or v.
Espen #6
Posted 19 October 2012 - 02:34 AM
Thanks, but it was so it would be compatible for Tekkit cause my friends and I play on it :P/>/>
I just found a ComputerCraft 1.21 on my drive and it supports getSides().
I'm not sure since when it was available, but if your Tekkit has turtles, then you should have getSides().

A possible reason for the confusion just came to mind:
If you typed "help rs" and didn't see a getSides() function, then that's because it's only listed on "help redstone", which is more up-to-date than the help-page for rs. But rs and redstone are the same API, so you should definitely have that function.^^
ChunLing #7
Posted 19 October 2012 - 03:12 AM
hehe, I just remembered (encountered while coding) the case where I have to use something other than i,v … when the for loop is inside another for loop that I need the i or v from.
stilldabomb #8
Posted 19 October 2012 - 07:59 AM
Thanks, but it was so it would be compatible for Tekkit cause my friends and I play on it :P/>/>
I just found a ComputerCraft 1.21 on my drive and it supports getSides().
I'm not sure since when it was available, but if your Tekkit has turtles, then you should have getSides().

A possible reason for the confusion just came to mind:
If you typed "help rs" and didn't see a getSides() function, then that's because it's only listed on "help redstone", which is more up-to-date than the help-page for rs. But rs and redstone are the same API, so you should definitely have that function.^^
Just noticed that said "redstone.getSides()"… XD
Ralnick #9
Posted 19 October 2012 - 11:06 AM
from a n00b.

Thank you so much for making this much faster and easier then going into LUA every time and telling it to open the side the modem is on.
now just run a program and done.
stilldabomb #10
Posted 19 October 2012 - 08:15 PM
You're so very welcome :P/>/>
ChunLing #11
Posted 25 October 2012 - 02:31 AM
It's not a program, it's not even a function, really. It's just a couple of lines you can use to open a modem to stick in a program that uses a modem. I prefer a full function so I can use the return to know whether or not there was a modem to open, but for some purposes this would be fine.
stilldabomb #12
Posted 27 October 2012 - 04:35 PM
What a crap program…y
Don't go thrashing because it's 3 lines of code. I made it super simple for people that are beginners with LUA.
Stop thrashing kid.
Noodle #13
Posted 27 October 2012 - 04:53 PM
This has already been made.. multiple (thousands+) times?
Tiin57 #14
Posted 27 October 2012 - 04:57 PM
This has already been made.. multiple (thousands+) times?
Seriously. Any half-decent coder could write this exact thing up in about two seconds. Get rid of this.
stilldabomb #15
Posted 27 October 2012 - 08:38 PM
This has already been made.. multiple (thousands+) times?
Seriously. Any half-decent coder could write this exact thing up in about two seconds. Get rid of this.
This has already been made.. multiple (thousands+) times?
I don't care how many times it's been made, there is no reason for you to be a complete douche and thrash just because I'm trying to help out some people that know little to no LUA. So leave.
Jajnick #16
Posted 27 October 2012 - 09:18 PM
To all the people who dislike this program and want to write a post about it:

Please note that critique and basically all forms of expressing dissatisfaction are strictly forbidden on our forums. You have no right to say anything bad about anyone or anyone's work, even though it's seriously shit and its author should feel shit. Doing so will not be tolerated by the society and results in loss of acceptance, trust and respect. Remember - no matter what, you are the only one who thinks bad, and we don't care about your opinion - this means that you may not express it. If you don't like it - go somewhere else, you aren't welcome here. Deal with it, or live treated like trash!
stilldabomb #17
Posted 27 October 2012 - 11:43 PM
people who know little to no lua?? like you??
Have you seen any of my projects? If you're gonna be a complete douche saying that I know little to no LUA then you should back it up with some proof kid.
Noodle #18
Posted 28 October 2012 - 01:22 AM
To all the people who dislike this program and want to write a post about it:

Please note that critique and basically all forms of expressing dissatisfaction are strictly forbidden on our forums. You have no right to say anything bad about anyone or anyone's work, even though it's seriously shit and its author should feel shit. Doing so will not be tolerated by the society and results in loss of acceptance, trust and respect. Remember - no matter what, you are the only one who thinks bad, and we don't care about your opinion - this means that you may not express it. If you don't like it - go somewhere else, you aren't welcome here. Deal with it, or live treated like trash!
I'm not thrashing… It's just unnecessary. If they want to learn these methods just read any rednet code.

EDIT: Here comes Cloudy…
stilldabomb #19
Posted 28 October 2012 - 07:15 AM
I know it's unnecissary, but I made it because when I sit in the ComputerCraft IRC there are like 10 people a day that say "How do you open a modem on all sides?"
ChunLing #20
Posted 28 October 2012 - 09:19 AM
Yeah…that happens. You might want to post it on a tutorials thread or something. Or not.
Tiin57 #21
Posted 28 October 2012 - 11:42 AM
I am not trashing this program because it stinks. I'm trashing it because it's useless. Any decent program that uses rednet will incorporate this code. So, any end users will never need to manually open a modem.
ficolas #22
Posted 28 October 2012 - 09:56 PM
This program didnt open it at all sides, the topic the first time I read it was

Rednet opener!!

code:
rednet.open("left")
print"opened!"

it needs to be at the left side
stilldabomb #23
Posted 29 October 2012 - 01:11 AM
I am not trashing this program because it stinks. I'm trashing it because it's useless. Any decent program that uses rednet will incorporate this code. So, any end users will never need to manually open a modem.
It's not a program, it's a snip-it of code for people that know little to no lua, I just get tired of people spamming OPs in the IRC.

This program didnt open it at all sides, the topic the first time I read it was

Rednet opener!!

code:
rednet.open("left")
print"opened!"

it needs to be at the left side
For one, this is not a program, for two, this snip-it of code never once said rednet.open("left") print"opened!".
Also, the post title is "Rednet opener! (Super simple!)" so you're reading a different post.
Cruor #24
Posted 29 October 2012 - 07:26 AM
Locked thread, no offense stilldabomb, but this asks for hate.

Edit: hmm nvm, moved to tutorials instead.
stilldabomb #25
Posted 30 October 2012 - 06:36 PM
Yeah, I thought about getting it moved to tutorials a while ago…
Cruor #26
Posted 31 October 2012 - 08:58 PM
Yeah, I thought about getting it moved to tutorials a while ago…

Dont think about it :P/>/> just report it and request it to be moved, im happy to move threads :3
Tiin57 #27
Posted 02 November 2012 - 10:52 AM
Unicorn king? Oh, master, I revere your excellence. :D/>/>
stilldabomb #28
Posted 02 November 2012 - 03:40 PM
Unicorn king? Oh, master, I revere your excellence. :D/>/>
XD, I just noticed what you ment by that, and I'm glad the fighting is over :)/>/>
justync7 #29
Posted 04 November 2012 - 09:32 AM
Don't be a skid.
It's 3 lines of code, you cant act like you're the only one that coded that.
stilldabomb #30
Posted 05 November 2012 - 01:45 PM
–snip-
I never said I did, I'm saying, the amount of people that are like "I don't want to type this! It's too long!" when it's really only 3 lines.