Jump to content




Very Basic Framework (Your First Peripheral)


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

#1 Casper7526

    OG of CC

  • Members
  • 362 posts

Posted 13 March 2012 - 06:17 PM

This framework was from the very first peripheral I made, it should work as I don't believe the API has changed.

Note #1: Doesn't use Forge Sprites/Textures
Note #2: Change everything to your own Names
Note #3: If this is too hard to understand, you SHOULDN'T be making a peripheral.

mod_Block.java
Spoiler
TileEntityName.java
Spoiler

BlockName.java
Spoiler


#2 Liraal

  • New Members
  • 477 posts
  • LocationPoland

Posted 13 March 2012 - 08:34 PM

I see I am a longer way from making a PDA that i thought I am :mellow:/>

#3 Hackingroelz

    Peripheral Designer

  • Members
  • 213 posts
  • Locationthe Nether(lands)

Posted 14 March 2012 - 09:06 PM

I''ve made my first peripheral. I know it works since peripheral.isPresent() returns true, but I have no idea how to call a method that I made. Could somebody explain this to me?

#4 Casper7526

    OG of CC

  • Members
  • 362 posts

Posted 14 March 2012 - 11:04 PM

peripheral.getMethods(side)
peripheral.call(side, method)

#5 ComputerCraftFan11

  • Members
  • 771 posts
  • LocationHawaii

Posted 01 April 2012 - 08:57 PM

How can I make a function or something to make the peripheral do something?

#6 bbqroast

  • Members
  • 124 posts

Posted 25 July 2012 - 10:12 PM

View PostComputerCraftFan11, on 01 April 2012 - 08:57 PM, said:

How can I make a function or something to make the peripheral do something?
See the TileEntityName.class example? In the getMethodNames() function it has an array of strings, the example has a single function "test". Say you wanted some functions for changing the block color, in that array you could create the functions setColorRed(), setColorGreen() like this:
public String[] getMethodNames()
	    {
	    return (new String[] { "setColorRed", "setColorGreen" });
	    }
Then in the call method function you can respond to them:
public Object[] callMethod(IComputerAccess icomputeraccess, int i, Object aobj[])
	    throws Exception
	    {
	    if (i == 0)
	    {
	    // Do logic for the setColorRed() function
	    } else if (i == 1) {
	    // Do logic for the setColorGreen() function
	    }
	    return null;
	    }
I believe "i" is the index of the function name in the array.
Note:You do all the peripheral programming in Java, not LUA.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users