Jump to content




Rednet opener! (Super simple!)

wireless utility lua

  • You cannot reply to this topic
29 replies to this topic

#1 stilldabomb

  • New Members
  • 110 posts

Posted 18 October 2012 - 05: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

#2 stilldabomb

  • New Members
  • 110 posts

Posted 18 October 2012 - 06: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.

#3 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 18 October 2012 - 10: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 by Espen, 18 October 2012 - 10:10 AM.


#4 stilldabomb

  • New Members
  • 110 posts

Posted 18 October 2012 - 02:25 PM

Thanks, but it was so it would be compatible for Tekkit cause my friends and I play on it :P/>

#5 ChunLing

  • Members
  • 2,027 posts

Posted 18 October 2012 - 07: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.

#6 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 19 October 2012 - 01:34 AM

View Poststilldabomb, on 18 October 2012 - 02:25 PM, said:

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.^^

#7 ChunLing

  • Members
  • 2,027 posts

Posted 19 October 2012 - 02: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.

#8 stilldabomb

  • New Members
  • 110 posts

Posted 19 October 2012 - 06:59 AM

View PostEspen, on 19 October 2012 - 01:34 AM, said:

View Poststilldabomb, on 18 October 2012 - 02:25 PM, said:

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

#9 Ralnick

  • New Members
  • 32 posts
  • Locationthe lighter side of Hell -- South Dakota

Posted 19 October 2012 - 10: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.

#10 stilldabomb

  • New Members
  • 110 posts

Posted 19 October 2012 - 07:15 PM

You're so very welcome :P/>

#11 ChunLing

  • Members
  • 2,027 posts

Posted 25 October 2012 - 01: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.

#12 stilldabomb

  • New Members
  • 110 posts

Posted 27 October 2012 - 03:35 PM

View Postficolas, on 24 October 2012 - 08:37 PM, said:

What a crap program...y

View Poststilldabomb, on 18 October 2012 - 06:18 AM, said:

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.

#13 Noodle

  • Members
  • 989 posts
  • LocationSometime.

Posted 27 October 2012 - 03:53 PM

This has already been made.. multiple (thousands+) times?

#14 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 27 October 2012 - 03:57 PM

View PostNoodle, on 27 October 2012 - 03:53 PM, said:

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.

#15 stilldabomb

  • New Members
  • 110 posts

Posted 27 October 2012 - 07:38 PM

View Posttiin57, on 27 October 2012 - 03:57 PM, said:

View PostNoodle, on 27 October 2012 - 03:53 PM, said:

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.

View PostNoodle, on 27 October 2012 - 03:53 PM, said:

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.

#16 Jajnick

  • New Members
  • 41 posts
  • LocationPoland

Posted 27 October 2012 - 08: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!

Posted Image



#17 stilldabomb

  • New Members
  • 110 posts

Posted 27 October 2012 - 10:43 PM

View Postficolas, on 27 October 2012 - 08:13 PM, said:

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.

#18 Noodle

  • Members
  • 989 posts
  • LocationSometime.

Posted 28 October 2012 - 12:22 AM

View PostJajnick, on 27 October 2012 - 08:18 PM, said:

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...

#19 stilldabomb

  • New Members
  • 110 posts

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?"

#20 ChunLing

  • Members
  • 2,027 posts

Posted 28 October 2012 - 09:19 AM

Yeah...that happens. You might want to post it on a tutorials thread or something. Or not.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users