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

Block API v0.7

Started by OmegaVest, 28 February 2013 - 07:38 AM
OmegaVest #1
Posted 28 February 2013 - 08:38 AM
Hello, and thank you for your interest in OmegasTech's new promotional product, the Block API.

This revolutionary program can turn any block into a peripheral! Wrap it like any other peripheral, and change its settings, or gather its data.

Contact your local OmegasTech representative for a FREE copy of our promotional material.[/salespitch]


Yep, this silly little API can wrap any adjacent block.

Doc:
Spoiler

block.wrap()  --  Wraps the block for manipulation
block.call(string side, string function, params[not a table, please]) -- Calls a specified function on a specified side.

b.activate(boolean) -- Powers or depowers the block's redstone. Use without a parameter to toggle the current state.
b.isActive() -- Checks the status of the block.
b.pulse(int count, int slp) -- Pulses the blocks signal count times and sleeps for slp seconds.

This is mostly just a silly thing that has, at times, helped me with larger projects. It turned 10 lines into 5 in one section, for instance.

Anyway, if you find this useful, please do not hesitate to pastebin this code, or download it below.

pastebin get nwf10MdP
or
Download


Changelog:
v0.7: Added .call to the
v0.6: Added .pulse to the function list.
v0.51: Fixed 1 error (Thanks Eric)
v0.5: Initial release.

Planned Features (if I find the time):
– Fix .call (There's some issues I'm working out, but it should work normally anyway)
– events (coroutines are kicking me you know where)
– installer (Probably in 1.0)
– blockPulse(int) Got it!
– setPower(int) and getPower()


Happy Coding!

PS. All you potential naysayers: I thought it was funny.
Eric #2
Posted 28 February 2013 - 08:47 AM
I think you're missing a "return bobble" in there somewhere
OmegaVest #3
Posted 28 February 2013 - 08:54 AM
…Possibly. Fixing.


EDIT: Fixed. Download locatons didn't change.
oeed #4
Posted 28 February 2013 - 09:13 PM
Hmmm… Interesting concept of 'wrapping' you got there. Still, not a bad idea though.
At first glance I thought you could detect the id of the block or what ever.
robhol #5
Posted 01 March 2013 - 01:45 AM
What would this be used for?
OmegaVest #6
Posted 01 March 2013 - 07:50 AM
Well, I used it for an RP2 disco-lights setup, but I'm certain there is a better use for it than that. And probably a less seizure-inducing one.
Minesoft #7
Posted 03 March 2013 - 04:40 AM
Good!
OmegaVest #8
Posted 13 March 2013 - 04:15 AM
Small Update: Added .pulse, which will pulse the blocks signal a number of times equal to its first parameter, and will sleep for a number of seconds equivalent to the second parameter, if you choose to provide one. If you do not provide it, the pulse will sleep for .25 seconds.

This update has been applied to the DB link and the pastebin. If you want a pervious version (why, exactly? This didn't break anything, I don't think) PM me and I will send you a link to it.
Jan #9
Posted 16 March 2013 - 11:23 PM
I think there should be peripheral functions for the block object, such as isPresent(), getType(), getMethods(), call() and wrap()
Also compare, dig, place, attack if the computer is a turtle :)/>
OmegaVest #10
Posted 17 March 2013 - 08:37 AM
Hmm. I'll have to go look at those.

Just out of curiosity, what do you mean by call()?

Also, I should mention that, should I continue to update this (I mean, come on! It's the redstone API with a shell around it!) I'm gonna first work on analog for 1.5. MOAR DISCO LIGHTS!
Jan #11
Posted 17 March 2013 - 08:44 AM
Just out of curiosity, what do you mean by call()?
It's a function in the peripheral API. for example to write hello on a screen: peripheral.call("left","write","hello")
OmegaVest #12
Posted 17 March 2013 - 08:51 AM
Ah. Maybe.
immibis #13
Posted 18 March 2013 - 08:49 PM
Just out of curiosity, what do you mean by call()?
It's what people used before we had this newfangled peripheral.wrap function.
OmegaVest #14
Posted 19 March 2013 - 10:17 AM
Oooookay! So, after this little discussion, and the inspiration for all this condescends in my thread, I add .call(side, func, params[not a table, working on it]). There's a surprise in there, even. No changes in location, previous versions still available.