Jump to content




Death's Programs!


18 replies to this topic

#1 Alice

  • Members
  • 429 posts
  • LocationBehind you.

Posted 11 November 2013 - 12:42 PM

This is going to be a post where I post all of my programs until I get a website hosted for them.
All of my programs are going to be random programs that you can use for any random reason.
Just send me a message or reply to this post if you have a suggestion/bug for me.
Peripherals program
Detects peripherals
Spoiler
More to come! A lot of them will be misc. programs I randomly thought of!
No pastebin, sorry!
Spoiler

Edited by Death, 13 December 2013 - 10:08 AM.


#2 TechMasterGeneral

  • Members
  • 149 posts
  • LocationUnited States

Posted 11 November 2013 - 03:43 PM

Pretty Cool... I may decide to use this in the program i'm working on... if your okay with that.. I'll put you in the credits.

#3 Alice

  • Members
  • 429 posts
  • LocationBehind you.

Posted 21 November 2013 - 12:11 PM

No problem. I plan on making a bunch more once I'm ungrounded.

#4 Alice

  • Members
  • 429 posts
  • LocationBehind you.

Posted 13 December 2013 - 08:58 AM

Bump for making Peripherals into an API.
Just change local api to local api = true!
Also, could someone test this please?

#5 Csstform

  • Members
  • 410 posts
  • LocationU.S.A.

Posted 13 December 2013 - 09:29 AM

I have one that works just as well, but only 6 lines of code. :P

#6 ardera

  • Members
  • 503 posts
  • LocationGermany

Posted 13 December 2013 - 09:30 AM

I think your "Detects Peripherals" program will crash when you launch it with api = true, because you set print to nil if api is true, and when you use print then, it will throw an "attempt to call nil" error, I think. Instead, use
print = function() end
It will set print to a clear function, that does nothing.

#7 Alice

  • Members
  • 429 posts
  • LocationBehind you.

Posted 13 December 2013 - 09:48 AM

Thanks; I can't test it right now, but I'm fixing the post.
Fixed, can someone test both the normal program using peripherals <someside> and peripherals, and try the API?

Edited by Death, 13 December 2013 - 09:49 AM.


#8 Csstform

  • Members
  • 410 posts
  • LocationU.S.A.

Posted 13 December 2013 - 09:54 AM

Does this do the same thing, or am I missing the point of yours? Yours IS more user freindly.

http://pastebin.com/2FbbdJur

Edited by Castform, 13 December 2013 - 09:55 AM.


#9 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 13 December 2013 - 10:00 AM

your code won't work. You redefine print as
print = function() end
, and then call back to that print function you just overwrote. I don't see why you are doing that...there's no point with the code you have shown.

#10 Alice

  • Members
  • 429 posts
  • LocationBehind you.

Posted 13 December 2013 - 10:02 AM

The program is able to be used as an API and as a program.
It's only overwritten if api is true, where you wouldn't want to have the text print to the screen.

Also, castform, I'm not able to use pastebin with proxy :D Please use hastebin or
Spoiler
Currently trying to find a way to implement into an API, but class is over so I will work on it later.

Edited by Death, 13 December 2013 - 10:08 AM.


#11 Csstform

  • Members
  • 410 posts
  • LocationU.S.A.

Posted 13 December 2013 - 10:38 AM

Spoiler


#12 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 13 December 2013 - 10:57 AM

 Castform, on 13 December 2013 - 10:38 AM, said:

function wrapPeripherals()
        peripheral.wrap("left")
        peripheral.wrap("right")
        peripheral.wrap("front")
        peripheral.wrap("back")
        peripheral.wrap("top")
        peripheral.wrap("bottom")
end

That accomplishes literally nothing at all.

#13 Csstform

  • Members
  • 410 posts
  • LocationU.S.A.

Posted 13 December 2013 - 12:42 PM

 Lyqyd, on 13 December 2013 - 10:57 AM, said:

 Castform, on 13 December 2013 - 10:38 AM, said:

function wrapPeripherals()
        peripheral.wrap("left")
        peripheral.wrap("right")
        peripheral.wrap("front")
        peripheral.wrap("back")
        peripheral.wrap("top")
        peripheral.wrap("bottom")
end

That accomplishes literally nothing at all.
I thought that's how you wrap peripherals. Hmm. Silly me, I thought I found something easy about programming.

#14 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 13 December 2013 - 03:41 PM

You have to do something with the value it returns. Otherwise, you're just creating and discarding six tables for no reason.

#15 Alice

  • Members
  • 429 posts
  • LocationBehind you.

Posted 13 December 2013 - 05:43 PM

This would be a better version of wrapping the peripherals anyway
local sides = rs.getSides()
for i=1, #sides do
peripheral.wrap(sides[i])
end
:D

#16 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 13 December 2013 - 06:46 PM

If it didn't have exactly the same problem as Castform's code, maybe. ;) I'm also not sure what you're doing with the redstone API there...

To be clear, "peripheral.wrap()" returns something. If you don't store that result somewhere, it simply gets discarded.

For example, let's say you wanted to recycle the "sides" table to hold the wrapped peripherals instead of just their names:

local sides = peripheral.getNames()
for i=1, #sides do
  sides[i] = peripheral.wrap(sides[i])
end


#17 Alice

  • Members
  • 429 posts
  • LocationBehind you.

Posted 13 December 2013 - 09:32 PM

I use the rs.getSides() function just to get a table with the sides.

#18 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 13 December 2013 - 09:49 PM

You're better off using peripheral.getNames since it gives you a table of the sides and network names of present peripherals, removing the need for presence checking (which is also redundant when type checking since if it is not present it returns nil, and nil never equals the type string you're checking)

Take a look at this example that I've made earlier. More info can be found on my thread under code snippets > peripheral search

Edited by theoriginalbit, 14 December 2013 - 01:37 AM.


#19 Alice

  • Members
  • 429 posts
  • LocationBehind you.

Posted 13 December 2013 - 10:52 PM

Cool, when I feel up to it I'll add it, but I'm just barely able to pop on and off Forums / IRC





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users